diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 97643947ad..c1f03c7868 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -1104,4 +1104,14 @@ q.pop c = Class.new(Thread) {def initialize() self.name = "foo"; super; end} assert_equal("foo", c.new {Thread.current.name}.value) end + + def test_thread_interrupt_for_killed_thread + assert_normal_exit(<<-_end, '[Bug #8996]', timeout: 5, timeout_error: nil) + trap(:TERM){exit} + while true + t = Thread.new{sleep 0} + t.raise Interrupt + end + _end + end end diff --git a/thread.c b/thread.c index 3ec4b900a7..473b6b686c 100644 --- a/thread.c +++ b/thread.c @@ -2090,6 +2090,13 @@ rb_threadptr_raise(rb_thread_t *th, int argc, VALUE *argv) else { exc = rb_make_exception(argc, argv); } + + /* making an exception object can switch thread, + so we need to check thread deadness again */ + if (rb_threadptr_dead(th)) { + return Qnil; + } + rb_threadptr_setup_exception(GET_THREAD(), exc, Qundef); rb_threadptr_pending_interrupt_enque(th, exc); rb_threadptr_interrupt(th); diff --git a/version.h b/version.h index 0628afac17..9ceb38e246 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.3.3" #define RUBY_RELEASE_DATE "2017-03-20" -#define RUBY_PATCHLEVEL 248 +#define RUBY_PATCHLEVEL 249 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3