- Notifications
You must be signed in to change notification settings - Fork5.4k
CI windows debugging: Bug 21398 ractor lock ordering issue hack#13851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
jhawthorn wants to merge5 commits intoruby:masterChoose a base branch fromjhawthorn:bug_21398_ractor_lock_ordering_issue_hack
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
CI windows debugging: Bug 21398 ractor lock ordering issue hack#13851
jhawthorn wants to merge5 commits intoruby:masterfromjhawthorn:bug_21398_ractor_lock_ordering_issue_hack
+133 −45
Conversation
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
…d_wakeup()In rb_ractor_sched_wait() (ex: Ractor.receive), we acquireRACTOR_LOCK(cr) and then thread_sched_lock(cur_th). However, on wakeupif we're a dnt, in thread_sched_wait_running_turn() we acquirethread_sched_lock(cur_th) after condvar wakeup and then RACTOR_LOCK(cr).This lock inversion can cause a deadlock with rb_ractor_wakeup_all()(ex: port.send(obj)), where we acquire RACTOR_LOCK(other_r) and thenthread_sched_lock(other_th).So, the error happens:nt 1: Ractor.receive rb_ractor_sched_wait() after condvar wakeup in thread_sched_wait_running_turn(): - thread_sched_lock(cur_th) (condvar) # acquires lock - rb_ractor_lock_self(cr) # deadlock here: tries to acquire, HANGSnt 2: port.send ractor_wakeup_all() - RACTOR_LOCK(port_r) # acquires lock - thread_sched_lock # tries to acquire, HANGSOne solution would be to rework `thread_sched_wait_running_turn()` with DNT's. I didn'tdo this because it would be a bigger architectural change. What I changed is to unlockRACTOR_LOCK before calling rb_ractor_sched_wakeup() in a pthread env. In a non-pthreadenv it's safe to hold this lock, and we should.Script that reproduces issue:```rubyrequire "async"class RactorWrapper def initialize@Ractor = Ractor.new do Ractor.recv # Ractor doesn't start until explicitly told to # Do some calculations fib = ->(x) { x < 2 ? 1 : fib.call(x - 1) + fib.call(x - 2) } fib.call(20) end end def take_async @ractor.send(nil) Thread.new { @ractor.value }.value endendAsync do |task| 10_000.times do |i| task.async do RactorWrapper.new.take_async puts i end endendexit 0```Fixes [Bug #21398]
launchable-appbot commentedJul 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
❌Tests Failed✖️no tests failed ✔️61861 tests passed(4 flakes) |
Sign up for freeto 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.
No description provided.