Only set locking thread once successful#9259
Merged
headius merged 2 commits intojruby:masterfrom Feb 24, 2026
Merged
Conversation
If the lock is acquired but we are immediately interrupted by another thread, it will be unlocked while leaving the lockingThread field set. This will cause all future locks by other fibers on that thread to trigger a deadlock error, since the lock will appear to have been acquired by a different fiber on that thread. Patch by @yamam. Fixes jruby#9218
In jruby#9218 a user discovered that thread interrupt during an attempt to lock a mutex may render that mutex unusable from any other fiber, even if it did not successfully lock. This spec tries to trigger that state by having one thread loop while triggering a raise interrupt on another thread that repeatedly locks a mutex from within fibers. This may not always fail when it is broken due to the timing issues involved in triggering the interrupt after the lock was acquired but before interrupts have been handled by the fiber, but 10x seems sufficient to trigger the bug on JRuby.
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.
If the
lockingThreadis set before handling interrupts, and those interrupts cause the lock to be unlocked, the lock state will be broken for future fibers on the same thread and potentially for other threads. We move the set oflockingThreadafter we are sure we've successfully locked without interrupt and are about to return.Fixes #9218