From: eregontp@... Date: 2017-11-29T21:49:47+00:00 Subject: [ruby-core:83986] [Ruby trunk Feature#14143] Thread.report_on_exception should be true by default Issue #14143 has been updated by Eregon (Benoit Daloze). Real-world libraries like Sidekiq implement their own thread exception handler: https://github.com/mperham/sidekiq/blob/a60a91d3dd857592a532965f0701d285f13f28f1/lib/sidekiq/util.rb#L15-L27 Interestingly this is named "safe_thread", probably alluding to the fact Thread.new is unsafe/dangerous as it just ignores errors silently. This would be much nicer with Thread.on_exception(&handler). However, I think Thread.on_exception should be a separate issue, extending on good defaults from this issue (then the default handler would just be to print to stderr). What matters most to me and [many rubyists](https://twitter.com/eregontp/status/935949287283884032) is that by default Ruby Threads do not die silently, and instead the programmer is given a good clue when a part of the program raises an error and it's never handled. Thread.report_on_exception = true by default would mean with no extra code there is already a good handling of exceptions in threads. Nobody should have to remember to always add Thread.report_on_exception = true or Thread.abort_on_exception = true on every Ruby program using Thread, or otherwise waste a lot of debugging time. I am telling this from experience: I am a PhD student working for 3 years on Ruby & concurrency, as well as a test suite maintainer. ---------------------------------------- Feature #14143: Thread.report_on_exception should be true by default https://bugs.ruby-lang.org/issues/14143#change-68065 * 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: