From: shyouhei@... Date: 2016-05-17T23:14:49+00:00 Subject: [ruby-core:75582] [Ruby trunk Feature#6647] Exceptions raised in threads should be logged Issue #6647 has been updated by Shyouhei Urabe. Charles Nutter wrote: > > Benoit, I advise you to compromise on the default value. Once this feature gets implemented, its default value could be flipped later I think. We technically can't do what is proposed here now, which is definitely worse than a wrong default. no? > > I am confused what it is we "can't" do right now. Do you mean: there's no reporting currently and we're seeking to add it...off by default but at least better than we have now? Yes. Sorry for my bad English. I wanted to say this is "better than nothing". I understand people want it with default on, and myself can live with that. However sticking to "default true, or no such feature" tactics can make this issue hard to land. Matz is not comfortable with this for years. We have just partially persuaded him about the functionality. I think this is a step forward. ---------------------------------------- Feature #6647: Exceptions raised in threads should be logged https://bugs.ruby-lang.org/issues/6647#change-58716 * Author: Charles Nutter * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- 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: ```ruby 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" ``` 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 ``` -- https://bugs.ruby-lang.org/ Unsubscribe: