Fix: add threading lock around JVM startup to prevent parallel connect crash (issue #60)#92
Open
HenryNebula wants to merge 3 commits intodevfrom
Open
Fix: add threading lock around JVM startup to prevent parallel connect crash (issue #60)#92HenryNebula wants to merge 3 commits intodevfrom
HenryNebula wants to merge 3 commits intodevfrom
Conversation
38c2e7e to
d7950e2
Compare
…t crash (issue #60) Multiple threads calling connect() simultaneously could both see isJVMStarted() return False and both attempt to start the JVM, causing a SIGSEGV crash. Add a threading.Lock to serialize JVM startup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The original implementation held _jvm_startup_lock during the entire startJVM() call. If JPype internally spawns threads during JVM initialization that re-enter the module (e.g., via imports), the non-reentrant Lock would deadlock. Refactored to only hold the lock briefly when checking/setting a flag, then run startJVM() outside the lock. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Worker threads that call connect() get attached to the JVM via jpype.attachThreadToJVM(). Without explicit detachment, these threads leave zombie Java threads that prevent JVM shutdown, causing CI to time out. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
80e25a4 to
fd83627
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #60: JVM crash when multiple threads call
connect()simultaneously.Changes
threading.Lock(_jvm_startup_lock) to serialize JVM startup in_jdbc_connect_jpype()if not isJVMStarted(): startJVM()) was not atomic, allowing two threads to both attempt to start the JVM causing a SIGSEGVTest plan
ParallelConnectTest.test_parallel_connects_after_jvm_startedintest/test_mock.pyParallelConnectTest.test_jvm_startup_lock_existsintest/test_mock.pyParallelConnectTest.test_parallel_connects_with_hsqldbintest/test_integration.pyCloses #60
Generated with Claude Code