[ruby-core:78415] [Ruby trunk Bug#12991] Documentation of Thread.abort_on_exception is wrong: it raises error again in main thread

From: tagomoris@...
Date: 2016-11-29 12:09:36 UTC
List: ruby-core #78415
Issue #12991 has been reported by Satoshi TAGOMORI.

----------------------------------------
Bug #12991: Documentation of Thread.abort_on_exception is wrong: it raises error again in main thread
https://bugs.ruby-lang.org/issues/12991

* Author: Satoshi TAGOMORI
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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.

```ruby
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.



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next