Project

General

Profile

Bug #7951

Cannot rescue SignalException in 1.9.3 or 2.0.0

Added by jamesotron (James Harton) over 4 years ago. Updated 15 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]
[ruby-core:52864]

Description

When running the example provided on http://www.ruby-doc.org/core-1.9.3/SignalException.html we find that neither Ruby 1.9.3p392 nor Ruby 2.0.0p0 are able to rescue SignalException:

$ cat <<EOF >signal_exception_test.rb
puts "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
begin
  Process.kill('HUP',Process.pid)
rescue SignalException => e
  puts "received Exception #{e}"
end
EOF

$ rvm 1.8.7,1.9.3,2.0.0 do ruby signal_exception_test.rb
1.8.7p371
received Exception SIGHUP
1.9.3p392
/Users/jnh/.rvm/scripts/set: line 20: 99759 Hangup: 1               "${args[@]}"
2.0.0p0
/Users/jnh/.rvm/scripts/set: line 20: 99816 Hangup: 1               "${args[@]}"

Associated revisions

Revision 39501
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • error.c: clarify a document of SignalException. Process.kill() doesn't have any guarantee when signal will be delivered. [Bug #7951]

Revision 39501
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • error.c: clarify a document of SignalException. Process.kill() doesn't have any guarantee when signal will be delivered. [Bug #7951]

Revision 39501
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • error.c: clarify a document of SignalException. Process.kill() doesn't have any guarantee when signal will be delivered. [Bug #7951]

Revision 39501
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • error.c: clarify a document of SignalException. Process.kill() doesn't have any guarantee when signal will be delivered. [Bug #7951]

Revision 39819
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • internal.h: added a declaration of ruby_kill().
  • thread.c (ruby_kill): helper function of kill().

  • signal.c (rb_f_kill): use ruby_kill() instead of kill().

  • signal.c (rb_f_kill): call rb_thread_execute_interrupts()
    to ensure that make SignalException if sent a signal
    to myself. [Bug #7951]

  • vm_core.h (typedef struct rb_thread_struct): added
    th->interrupt_cond.

  • thread.c (rb_threadptr_interrupt_common): added to
    initialization of th->interrupt_cond.

  • thread.c (thread_create_core): ditto.

  • test/ruby/test_signal.rb (TestSignal#test_hup_me): test for
    the above.

Revision 39819
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • internal.h: added a declaration of ruby_kill().
  • thread.c (ruby_kill): helper function of kill().

  • signal.c (rb_f_kill): use ruby_kill() instead of kill().

  • signal.c (rb_f_kill): call rb_thread_execute_interrupts()
    to ensure that make SignalException if sent a signal
    to myself. [Bug #7951]

  • vm_core.h (typedef struct rb_thread_struct): added
    th->interrupt_cond.

  • thread.c (rb_threadptr_interrupt_common): added to
    initialization of th->interrupt_cond.

  • thread.c (thread_create_core): ditto.

  • test/ruby/test_signal.rb (TestSignal#test_hup_me): test for
    the above.

Revision 39819
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • internal.h: added a declaration of ruby_kill().
  • thread.c (ruby_kill): helper function of kill().

  • signal.c (rb_f_kill): use ruby_kill() instead of kill().

  • signal.c (rb_f_kill): call rb_thread_execute_interrupts()
    to ensure that make SignalException if sent a signal
    to myself. [Bug #7951]

  • vm_core.h (typedef struct rb_thread_struct): added
    th->interrupt_cond.

  • thread.c (rb_threadptr_interrupt_common): added to
    initialization of th->interrupt_cond.

  • thread.c (thread_create_core): ditto.

  • test/ruby/test_signal.rb (TestSignal#test_hup_me): test for
    the above.

Revision 39819
Added by kosaki (Motohiro KOSAKI) over 4 years ago

  • internal.h: added a declaration of ruby_kill().
  • thread.c (ruby_kill): helper function of kill().

  • signal.c (rb_f_kill): use ruby_kill() instead of kill().

  • signal.c (rb_f_kill): call rb_thread_execute_interrupts()
    to ensure that make SignalException if sent a signal
    to myself. [Bug #7951]

  • vm_core.h (typedef struct rb_thread_struct): added
    th->interrupt_cond.

  • thread.c (rb_threadptr_interrupt_common): added to
    initialization of th->interrupt_cond.

  • thread.c (thread_create_core): ditto.

  • test/ruby/test_signal.rb (TestSignal#test_hup_me): test for
    the above.

Revision 59066
Added by ko1 (Koichi Sasada) 12 days ago

remove ruby_kill() introduced for [Bug #7951].

  • thread.c (rbuy_kill): removed. This function is used
    with SIGSEGV, SIGBUS, SIGKILL, SIGILL, SIGFPE and SIGSTOP
    and these signals are affect immediately. So that `kill(2)'
    is enough for them.

  • signal.c (rb_f_kill): ditto.

  • vm_core.h (rb_thread_t::interrupt_cond): removed because
    only `ruby_kill()' uses this field.

  • test/ruby/test_signal.rb: Without this patch sending SIGSTOP to own
    process wait another interrupt even if another process sends SIGCONT.

History

#1 [ruby-core:52887] Updated by kosaki (Motohiro KOSAKI) over 4 years ago

Following modified script works fine. That is a issue of YARV signal handling.

puts "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
begin
Process.kill('HUP',Process.pid)
sleep 0.1
rescue SignalException => e
puts "received Exception #{e}"
end

#2 Updated by kosaki (Motohiro KOSAKI) over 4 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39501.
James, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • error.c: clarify a document of SignalException. Process.kill() doesn't have any guarantee when signal will be delivered. [Bug #7951]

#3 [ruby-core:52888] Updated by kosaki (Motohiro KOSAKI) over 4 years ago

I changed a doc because the example has a mistake of usage of Process.kill(). Process.kill() doesn't have any guarantee when signal will be delivered.

#4 Updated by ko1 (Koichi Sasada) 15 days ago

  • Description updated (diff)

Also available in: Atom PDF