From: headius@... Date: 2017-11-29T20:34:00+00:00 Subject: [ruby-core:83983] [Ruby trunk Feature#14143] Thread.report_on_exception should be true by default Issue #14143 has been updated by headius (Charles Nutter). Perhaps "on by default" would be more palatable to people if we could also specify *how* to handle these unhandled exceptions? In Java, all threads will report a bubbled-out exception if you do not specify a handler for those exceptions. The handler can be set on a global basis or per-thread. So basically, the default is that bubbled exceptions get fed to a default handler that reports thread death. In Ruby, it might look like this: ```ruby Thread.report_on_exception = true # default Thread.on_exception {|ex| handle ex in app-appropriate way} ``` Report would then basically mean "send the exception to the default handler" and you can change the handler to something that logs to disk or to some online service or whatever. PROS: * Consistent reporting of exceptions from threads that specify no handler. * Threads won't quietly die anymore. * Threads can be made to quietly die or do something else with bubbled exceptions, on a local OR global basis CONS: * Existing code that depends on threads quietly dying will now see some error reporting (I'd recommend one line, with full trace in verbose mode) ---------------------------------------- Feature #14143: Thread.report_on_exception should be true by default https://bugs.ruby-lang.org/issues/14143#change-68062 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Extracted from #6647 to focus on the default value now that the feature is implemented. I strongly believe we should have Thread.report_on_exception = true by default. It only adds some extra stderr output for apps which let threads die, which is very rarely intended. If it is intended, then one can use Thread.current.report_on_exception = false to clarify it's OK for that thread to die and the failure is handled by the app on Thread#join. I enabled Thread.report_on_exception=true by default in ruby/spec, see https://github.com/ruby/spec/pull/517, the only cases needing Thread.current.report_on_exception=false are the specs testing report_on_exception itself and Thread#join/value/status/raise. Enabling it for test-all shows a fair amount of extra output and failures, which I would bet some of them are bugs in the tests (I already found one, r60854 & r60870), and other tests should simply more carefully test what they expect (for instance assert_raise() inside the Thread just around the code raising an exception and join the Thread). I am willing to help to reduce the extra output and failures in test-all, but I would like a OK from Matz to try enabling Thread.report_on_exception by default. Dear Matz, do you think it is reasonable to show exceptions killing threads on stderr by default, instead of silently swallowing them until Thread#join ? (if there is ever a Thread#join ..., often not or too late, when the rest of the application has crashed) -- https://bugs.ruby-lang.org/ Unsubscribe: