Skip to content

Commit 66312ad

Browse files
jhawthornfroydnj
andauthored
Re-initialize vm->ractor.sched.lock after fork (ruby#11372)
[Bug #20633] Re-initialize vm->ractor.sched.lock after fork Previously under certain conditions it was possible to encounter a deadlock in the forked child process if ractor.sched.lock was held. Co-authored-by: Nathan Froyd <[email protected]>
1 parent 4d11a09 commit 66312ad

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

bootstraptest/test_fork.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,25 @@
7575
end
7676
}, '[ruby-dev:44005] [Ruby 1.9 - Bug #4950]'
7777

78+
assert_equal 'ok', %q{
79+
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
80+
81+
Thread.new do
82+
loop { sleep 0.0001 }
83+
end
84+
85+
10.times do
86+
pid = fork{ exit!(0) }
87+
deadline = now + 1
88+
until Process.waitpid(pid, Process::WNOHANG)
89+
if now > deadline
90+
Process.kill(:KILL, pid)
91+
raise "failed"
92+
end
93+
sleep 0.001
94+
end
95+
rescue NotImplementedError
96+
end
97+
:ok
98+
}, '[Bug #20670]'
99+

thread_pthread.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,7 @@ thread_sched_atfork(struct rb_thread_sched *sched)
15301530
}
15311531
vm->ractor.sched.running_cnt = 0;
15321532

1533+
rb_native_mutex_initialize(&vm->ractor.sched.lock);
15331534
// rb_native_cond_destroy(&vm->ractor.sched.cond);
15341535
rb_native_cond_initialize(&vm->ractor.sched.cond);
15351536
rb_native_cond_initialize(&vm->ractor.sched.barrier_complete_cond);

0 commit comments

Comments
 (0)