diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-25 21:59:30 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-25 21:59:30 +0000 |
commit | 70a8a6d3eb20e4b251191d8cae06ee2453458253 (patch) | |
tree | 645ffff26e0f1635b0000705c170ab3f11ba30a4 /test/ruby/test_signal.rb | |
parent | 49309733e2403911c5812cd4f93754058cb57524 (diff) | |
download | ruby-70a8a6d3eb20e4b251191d8cae06ee2453458253.tar.gz |
thread_pthread.c: main thread always gets hit by signals
We need to ensure Signal.trap handlers can function if the main
thread is sleeping after a subthread has grabbed sigwait_fd,
but later exited.
Consider the following timeline:
main_thread sub-thread
-----------------------------------------
Signal.trap() { ... }
get sigwait_fd
ppoll on sigwait_fd
native_cond_sleep
(via pthread_cond_wait)
ppoll times-out
put sigwait_fd
sub-thread exits
only thread alive
SIGNAL HITS
The problem is pthread_cond_wait cannot return EINTR,
so we can never run the Signal.trap handler. So we
will avoid using native_cond_sleep in the main thread
and always use ppoll to sleep when in the main thread.
This can guarantee the main thread remains aware of
signals; even if it cannot safely read off sigwait_fd
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_signal.rb')
-rw-r--r-- | test/ruby/test_signal.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb index b8a20d945c..425dc26574 100644 --- a/test/ruby/test_signal.rb +++ b/test/ruby/test_signal.rb @@ -369,4 +369,24 @@ class TestSignal < Test::Unit::TestCase ensure trap(:CHLD, old) if Signal.list['CHLD'] end + + def test_sigwait_fd_unused + t = EnvUtil.apply_timeout_scale(0.1) + assert_separately([], <<-End) + tgt = $$ + trap(:TERM) { exit(0) } + e = "Process.daemon; sleep #{t * 2}; Process.kill(:TERM,\#{tgt})" + term = [ '#{EnvUtil.rubybin}', '--disable=gems', '-e', e ] + t2 = Thread.new { sleep } # grab sigwait_fd + Thread.pass until t2.stop? + Thread.new do + sleep #{t} + t2.kill + t2.join + end + Process.spawn(*term) + # last thread remaining, ensure it can react to SIGTERM + loop { sleep } + End + end if Process.respond_to?(:kill) && Process.respond_to?(:daemon) end |