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 <froydnj@gmail.com>
This commit is contained in:
John Hawthorn 2024-08-08 02:10:15 -07:00
parent 908305a297
commit 87a85550ed
Notes: git 2024-08-13 18:52:41 +00:00
2 changed files with 23 additions and 0 deletions

View File

@ -75,3 +75,25 @@ assert_equal '[1, 2]', %q{
end
}, '[ruby-dev:44005] [Ruby 1.9 - Bug #4950]'
assert_equal 'ok', %q{
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Thread.new do
loop { sleep 0.0001 }
end
10.times do
pid = fork{ exit!(0) }
deadline = now + 1
until Process.waitpid(pid, Process::WNOHANG)
if now > deadline
Process.kill(:KILL, pid)
raise "failed"
end
sleep 0.001
end
rescue NotImplementedError
end
:ok
}, '[Bug #20670]'

View File

@ -1556,6 +1556,7 @@ thread_sched_atfork(struct rb_thread_sched *sched)
}
vm->ractor.sched.running_cnt = 0;
rb_native_mutex_initialize(&vm->ractor.sched.lock);
// rb_native_cond_destroy(&vm->ractor.sched.cond);
rb_native_cond_initialize(&vm->ractor.sched.cond);
rb_native_cond_initialize(&vm->ractor.sched.barrier_complete_cond);