Issue #15644 has been reported by kke (Kimmo Lehto).

----------------------------------------
Bug #15644: ThreadsWait problems with Thread#report_on_exception
https://bugs.ruby-lang.org/issues/15644

* Author: kke (Kimmo Lehto)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
ThreadsWait spawns a new thread for waiting on a thread:

```
  # thwait.rb:87
  def join_nowait(*threads)
    threads.flatten!
    @threads.concat threads
    for th in threads
      Thread.start(th) do |t|
        begin
          t.join
        ensure
          @wait_queue.push t
        end
      end
    end
  end
```

As `thread.join` raises the exception from the thread, it will trigger a thread exception report.

If the thread was using `report_on_exception = false`, the wait thread will report the exception anyway.

If the thread was using `report_on_exception = true`, both threads will report the exception.

I think this could be fixed by always setting `report_on_exception = false` for the wait thread.

# Example 1

```
require 'thwait'

thread = Thread.new do
  Thread.current.report_on_exception = false
  raise "Foo"
end

ThreadsWait.all_waits(thread) do |terminated_thread|
  puts "Thread #{terminated_thread} terminated"
end
```

## Expected result

No exception reports

## Actual result

The wait thread will report the exception


# Example 2

```
require 'thwait'

thread = Thread.new do
  raise "Foo"
end

ThreadsWait.all_waits(thread) do |terminated_thread|
  puts "Thread #{terminated_thread} terminated"
end
```

## Expected result

One exception report

## Actual result

Two exception reports




-- 
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>