Skip to content

Commit

Permalink
Don't clear pending interrupts in the parent process. (#10365)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 26, 2024
1 parent 0c62eb2 commit a7ff264
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion process.c
Expand Up @@ -1682,7 +1682,6 @@ before_fork_ruby(void)
static void
after_fork_ruby(rb_pid_t pid)
{
rb_threadptr_pending_interrupt_clear(GET_THREAD());
if (pid == 0) {
// child
clear_pid_cache();
Expand Down
21 changes: 21 additions & 0 deletions test/ruby/test_process.rb
Expand Up @@ -2828,4 +2828,25 @@ def test_concurrent_group_and_pid_wait
[t1, t2, t3].each { _1&.join rescue nil }
[long_rpipe, long_wpipe, short_rpipe, short_wpipe].each { _1&.close rescue nil }
end if defined?(fork)

def test_handle_interrupt_with_fork
Thread.handle_interrupt(RuntimeError => :never) do
Thread.current.raise(RuntimeError, "Queued error")

assert_predicate Thread, :pending_interrupt?

pid = Process.fork do
if Thread.pending_interrupt?
exit 1
end
end

_, status = Process.waitpid2(pid)
assert_predicate status, :success?

assert_predicate Thread, :pending_interrupt?
end
rescue RuntimeError
# Ignore.
end if defined?(fork)
end
1 change: 1 addition & 0 deletions thread.c
Expand Up @@ -4725,6 +4725,7 @@ void
rb_thread_atfork(void)
{
rb_thread_t *th = GET_THREAD();
rb_threadptr_pending_interrupt_clear(th);
rb_thread_atfork_internal(th, terminate_atfork_i);
th->join_list = NULL;
rb_fiber_atfork(th);
Expand Down

0 comments on commit a7ff264

Please sign in to comment.