Bug #12991
closedDocumentation of Thread.abort_on_exception is wrong: it raises error again in main thread
Description
Currently, ruby doc says that:
When set to true, all threads will abort (the process will exit(0)) if an exception is raised in any thread.
But actually, the error raised in thread (with abort_on_exception = true) will be re-raised in main thread.
If main thread is running in begin-rescue for that error, the process (and other threads) will NOT abort.
sleeping = false
Thread.abort_on_exception = true
th = Thread.new do
sleep 0.1 until sleeping
raise "yay"
end
begin
sleeping = true
sleep 5
rescue => e
p(here: "rescue in main thread", error: e)
end
p "foo!"
This script shows "p" result and "foo!".
I think the document is misleading.
Updated by nobu (Nobuyoshi Nakada) over 7 years ago
- Status changed from Open to Closed
Applied in changeset r56928.
thread.c: fix doc of abort_on_exception [ci skip]
-
thread.c (rb_thread_s_abort_exc, rb_thread_s_abort_exc_set):
[DOC] the raised exception will be re-raised in the main thread,
and then follows the ordinary exception sequence, exit status is
not 0. [ruby-core:78415] [Bug #12991] -
thread.c (rb_thread_abort_exc_set): ditto.
Updated by nobu (Nobuyoshi Nakada) over 7 years ago
- Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED
Updated by usa (Usaku NAKAMURA) over 7 years ago
- Backport changed from 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: REQUIRED, 2.2: DONE, 2.3: REQUIRED
ruby_2_2 r57213 merged revision(s) 56928.
Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago
- Backport changed from 2.1: REQUIRED, 2.2: DONE, 2.3: REQUIRED to 2.1: REQUIRED, 2.2: DONE, 2.3: DONE
ruby_2_3 r57568 merged revision(s) 56928.