Skip to content

Narrow deadlock check for sibling fibers locking mutex#9226

Merged
headius merged 2 commits intojruby:masterfrom
headius:narrow_fiber_deadlock_check
Feb 10, 2026
Merged

Narrow deadlock check for sibling fibers locking mutex#9226
headius merged 2 commits intojruby:masterfrom
headius:narrow_fiber_deadlock_check

Conversation

@headius
Copy link
Copy Markdown
Member

@headius headius commented Feb 10, 2026

Fix and specs for when multiple sibling fibers from the same thread attempt to lock the same mutex.

Additional fix to cover the unreported case of two separate fibers both locking (original case from #9218 was parent thread locks and then a fiber locks). This is the second case added in the specs.

* Only raise deadlock error when two different fibers from the same
  thread attempt to lock (jruby#9218).
* Store the real parent thread as the locking thread for deadlock
  checks (fixes second case added in spec).

Fixes jruby#9218
@headius headius added this to the JRuby 10.0.4.0 milestone Feb 10, 2026
@headius headius merged commit a66cf51 into jruby:master Feb 10, 2026
78 of 79 checks passed
@headius headius deleted the narrow_fiber_deadlock_check branch February 10, 2026 21:33
headius added a commit to headius/jruby that referenced this pull request Feb 24, 2026
In jruby#9226 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaFX AnimationTimer + Mutex.synchronize triggers “deadlock; lock already owned by another fiber belonging to the same thread” on JRuby 10.0.3.0

1 participant