Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-1964

Java binding crashes when sessions are closed in a different thread

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: WT2.7.0
    • Labels:
      None
    • # Replies:
      8
    • Last comment by Customer:
      true

      Description

      The documentation for multithreading states that Sessions are allowed to be shared across threads, as long as access is synchronized so that the same handle isn't being operated on by more than one thread at a time. This seems like a useful semantic, so I tried creating a cache for sessions and it is working, except that when I close the session handles at the end of the program, it segfaults instead of closing gracefully. The attached file is a minimal test case that simply creates two sessions and then closes them in the main thread with connection.close().

      I don't fully understand what is going on, but based on googling around, it sounds like the problem is that the JNIEnv is specific to a single thread. The swig binding uses the JNIEnv of the thread that created the Session to close it - I think instead it must be the JNIEnv of the current thread that is doing the close.

      1. Example.java
        0.9 kB
        Greg Rogers
      2. Example2.java
        1 kB
        Donald Anderson

        Issue Links

          Activity

          Hide
          donald.anderson Donald Anderson added a comment -

          Thanks for the bug report with test case!

          To handle the general case of closing a connection (or session) and wanting all subordinate sessions (or cursors) to also be closed, we use a simple callback mechanism. As you discovered, that uses the original JNIEnv, which is saved in the session. That's clearly doesn't work in this case - I'll see if we can use the JNIEnv saved in the connection.

          Show
          donald.anderson Donald Anderson added a comment - Thanks for the bug report with test case! To handle the general case of closing a connection (or session) and wanting all subordinate sessions (or cursors) to also be closed, we use a simple callback mechanism. As you discovered, that uses the original JNIEnv, which is saved in the session. That's clearly doesn't work in this case - I'll see if we can use the JNIEnv saved in the connection.
          Hide
          donald.anderson Donald Anderson added a comment -

          Greg Rogers, if you explicitly close the sessions, there will not be a crash. I've attached Example2.java to show this. It's still a problem that an implicit close causes a crash.

          Show
          donald.anderson Donald Anderson added a comment - Greg Rogers , if you explicitly close the sessions, there will not be a crash. I've attached Example2.java to show this. It's still a problem that an implicit close causes a crash.
          Hide
          grogers Greg Rogers added a comment -

          That doesn't seem to help, Example2 still crashes most of the time for me. I'm currently using WT 2.5.3, I can upgrade to the latest and see if that makes a difference (I didn't see any changes that would have been relevant though).

          Show
          grogers Greg Rogers added a comment - That doesn't seem to help, Example2 still crashes most of the time for me. I'm currently using WT 2.5.3, I can upgrade to the latest and see if that makes a difference (I didn't see any changes that would have been relevant though).
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'}

          Message: WT-1964. For Java, handle cases where a session or cursor is closed
          when the thread that open it no longer exists. Add tests to kill
          threads that have open cursors and sessions.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/df854884079e1839d3353483c4988dd74fb7ecd3

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'} Message: WT-1964 . For Java, handle cases where a session or cursor is closed when the thread that open it no longer exists. Add tests to kill threads that have open cursors and sessions. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/df854884079e1839d3353483c4988dd74fb7ecd3
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'}

          Message: WT-1964. Simplify references to JAVA_CALLBACK->jnienv to promote readability.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/2e9f552fd873eae4a4dee9540cb3847fe12efa6a

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'} Message: WT-1964 . Simplify references to JAVA_CALLBACK->jnienv to promote readability. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/2e9f552fd873eae4a4dee9540cb3847fe12efa6a
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'agorrod', u'name': u'Alex Gorrod', u'email': u'alexander.gorrod@mongodb.com'}

          Message: Merge pull request #2031 from wiredtiger/java-thread-close

          WT-1964: In Java fix session/cursor close in different thread than open
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/4e0fe590cf7b2706317d88a6057454ac2b4fac52

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'agorrod', u'name': u'Alex Gorrod', u'email': u'alexander.gorrod@mongodb.com'} Message: Merge pull request #2031 from wiredtiger/java-thread-close WT-1964 : In Java fix session/cursor close in different thread than open Branch: develop https://github.com/wiredtiger/wiredtiger/commit/4e0fe590cf7b2706317d88a6057454ac2b4fac52
          Hide
          donald.anderson Donald Anderson added a comment -

          Greg Rogers, I think this merge in the WT develop branch should resolve this issue. The next release should pick it up.

          Show
          donald.anderson Donald Anderson added a comment - Greg Rogers , I think this merge in the WT develop branch should resolve this issue. The next release should pick it up.
          Hide
          donald.anderson Donald Anderson added a comment -

          This should be fixed by the changes to how we save/reuse JNIEnv.

          Show
          donald.anderson Donald Anderson added a comment - This should be fixed by the changes to how we save/reuse JNIEnv.

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                1 year, 51 weeks, 4 days ago
                Date of 1st Reply: