From: "headius (Charles Nutter)" Date: 2013-10-03T04:38:51+09:00 Subject: [ruby-core:57617] [ruby-trunk - Feature #6647] Exceptions raised in threads should be logged Issue #6647 has been updated by headius (Charles Nutter). ko1 (Koichi Sasada) wrote: > Sorry, it is not same, but we can consier that. > > BTW, I think it true as default is good idea. So to summarize: * Exceptions will log when they bubble out of a thread, as with -d, unless Thread#report_on_exception == false * Thread#report_on_exception defaults to true Can we do this for 2.1? > IMO, inter-thread communication via exception with Thread#join should be bad idea. +1 I had originally wanted something similar to Java, where you can set an "unhandled exception handler" for any thread. That would cover all cases, and the default case would be to just report the error. I was unsuccessful in specifying it because I wasn't sure how it should interact with abort_on_exception=. ---------------------------------------- Feature #6647: Exceptions raised in threads should be logged https://bugs.ruby-lang.org/issues/6647#change-42230 Author: headius (Charles Nutter) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: current: 2.1.0 Many applications and users I have dealt with have run into bugs due to Ruby's behavior of quietly swallowing exceptions raised in threads. I believe this is a bug, and threads should always at least log exceptions that bubble all the way out and terminate them. The implementation should be simple, but I'm not yet familiar enough with the MRI codebase to provide a patch. The exception logging should be logged in the same way top-level exceptions get logged, but perhaps with information about the thread that was terminated because of the exception. Here is a monkey patch that simulates what I'm hoping to achieve with this bug: class << Thread alias old_new new def new(*args, &block) old_new(*args) do |*bargs| begin block.call(*bargs) rescue Exception => e raise if Thread.abort_on_exception || Thread.current.abort_on_exception puts "Thread for block #{block.inspect} terminated with exception: #{e.message}" puts e.backtrace.map {|line| " #{line}"} end end end end Thread.new { 1 / 0 }.join puts "After thread" __END__ Output: system ~/projects/jruby $ ruby thread_error.rb Thread for block # terminated with exception: divided by 0 thread_error.rb:17:in `/' thread_error.rb:17 thread_error.rb:7:in `call' thread_error.rb:7:in `new' thread_error.rb:5:in `initialize' thread_error.rb:5:in `old_new' thread_error.rb:5:in `new' thread_error.rb:17 After thread -- http://bugs.ruby-lang.org/