Project

General

Profile

Actions

Bug #13916

closed

Race condition when sending a signal to a new fork

Added by russelldavis (Russell Davis) over 6 years ago. Updated about 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:82853]

Description

To reproduce, run this script:

1_000_000.times do |i|
  pid = fork {sleep}
  puts pid
  Process.kill(:TERM, pid)
  Process.wait(pid)
end

Expected behavior: it should print a million pids and then exit.

Actual behavior: after some number of iterations, it freezes on the call to Process.wait, because the fork never got killed by the TERM signal. (I verified with ps that the pid it froze on is still running.)

Updated by normalperson (Eric Wong) over 6 years ago

wrote:

https://bugs.ruby-lang.org/issues/13916

Oops, I don't think we block signals properly for plain fork' (vs spawn').
We need to use pthread_sigmask / sigprocmask to block signal.

I am testing this (slowly) and going to take a break while it
runs:

https://80x24.org/spew/20170919223250.22840-1-e@80x24.org/raw

Actions #2

Updated by Anonymous over 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59975.


process: block/unblock signals around fork

As with forking for execve(2) in spawn', we must block signals to ensure they are handled correctly in a freshly fork'-ed child.

  • process.c (retry_fork_ruby): block/unblock signals around fork
    (rb_fork_ruby): re-enable signals in forked child

  • test/ruby/test_process.rb (test_forked_child_signal): new test
    [ruby-core:82883] [Bug #13916]

    Thanks to Russell Davis for the bug report and test case.

Updated by normalperson (Eric Wong) over 6 years ago

  • Status changed from Closed to Open
  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED

backport status change

Updated by normalperson (Eric Wong) over 6 years ago

  • Status changed from Open to Closed

closing to trigger backport of r59975

Updated by nagachika (Tomoyuki Chikanaga) about 6 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

ruby_2_4 r62665 merged revision(s) 59975.

Updated by usa (Usaku NAKAMURA) about 6 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: REQUIRED, 2.3: DONE, 2.4: DONE

ruby_2_3 r62816 merged revision(s) 59975.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0