Forum: Ruby-core [ruby-trunk - Bug #6647][Open] Exceptions raised in threads should be logged

F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-06-26 00:22
(Received via mailing list)
Issue #6647 has been reported by headius (Charles Nutter).

----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-06-26 00:25
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


FWIW, precedent: Java threads log their exceptions by default. I have
*never* found the feature to be a bother, and it makes it nearly
impossible to ignore fatally-flawed thread logic that spins up and fails
lots of threads.
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-27455

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 rue (Eero Saynatkari) (Guest)
on 2012-06-26 00:45
(Received via mailing list)
Issue #6647 has been updated by rue (Eero Saynatkari).


headius (Charles Nutter) wrote:
> 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.

I have had to set .abort_on_exception more times than I care to
remember.

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

$stderr/warn, but this would improve the current situation
significantly.

Can significant upgrade problems be expected if .abort_on_exception
defaulted to true? This would seem to be the behaviour to suit most
users.
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-27456

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (regularfry)
on 2012-06-26 11:00
(Received via mailing list)
On 25/06/12 23:44, rue (Eero Saynatkari) wrote:
>
> Issue #6647 has been updated by rue (Eero Saynatkari).
>
>
> headius (Charles Nutter) wrote:
>> 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.
>
> I have had to set .abort_on_exception more times than I care to remember.

Agreed.  It's one of the things I check for in code review.  Consider
this a +1 from me.

>
>>        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}"}
>
> $stderr/warn, but this would improve the current situation significantly.
>
> Can significant upgrade problems be expected if .abort_on_exception defaulted to
true? This would seem to be the behaviour to suit most users.

That sounds a little extreme, although I wouldn't object.  I'd be happy
with them not being silently swallowed.

--
Alex
18813f71506ebad74179bf8c5a136696?d=identicon&s=25 Eric Wong (Guest)
on 2012-06-27 04:12
(Received via mailing list)
Alex Young <alex@blackkettle.org> wrote:
> On 25/06/12 23:44, rue (Eero Saynatkari) wrote:
> >Issue #6647 has been updated by rue (Eero Saynatkari).
> >
> >$stderr/warn, but this would improve the current situation significantly.
> >
> >Can significant upgrade problems be expected if .abort_on_exception defaulted
to true? This would seem to be the behaviour to suit most users.
>
> That sounds a little extreme, although I wouldn't object.  I'd be
> happy with them not being silently swallowed.

I think aborting the whole process is extreme (though, I usually do
it myself).

I would very much like to see this via $stderr/warn, though.
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 rue (Eero Saynatkari) (Guest)
on 2012-06-27 13:27
(Received via mailing list)
Issue #6647 has been updated by rue (Eero Saynatkari).


normalperson (Eric Wong) wrote:
>
>  I think aborting the whole process is extreme (though, I usually do
>  it myself).

You are probably correct. Reconsidering the issue, the benefit of
raising
is probably not enough to offset that, thus leaving the $stderr/warn as
the
better choice.

--
Eero
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-27519

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
6c06915d9aa00cd5c7d4acfb27cdd4e9?d=identicon&s=25 nahi (Hiroshi Nakamura) (Guest)
on 2012-07-14 11:12
(Received via mailing list)
Issue #6647 has been updated by nahi (Hiroshi Nakamura).

Category set to core
Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)
Target version set to 2.0.0

Discussions ad CRuby dev meeting at 14th July.

 * We can understand the requirement. (We understood that the
requirement is dumping something without raising when
Thread#abort_on_exception = false)
 * Writing to STDERR could cause problem with existing applications so
we should take care about it.
 * rb_warn() instead of puts would be good because we already using
rb_warns.

Matz, do you mind if we dump Thread error with rb_warn if
Thread#abort_on_exception = false?
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-28068

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-09-10 19:45
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


Any update on this?
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-29234

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-10-14 22:04
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


Ping! This came up in JEG's talk at Aloha RubyConf as a recommendation
(specifically, set abort_on_exception globally to ensure failed threads
don't quietly disappear). Ruby should not allow threads to quietly fail.
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-30671

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
02da662c083396641da96c1d32fc86ed?d=identicon&s=25 kosaki (Motohiro KOSAKI) (Guest)
on 2012-10-15 04:24
(Received via mailing list)
Issue #6647 has been updated by kosaki (Motohiro KOSAKI).


I think "exception raised" callback is better way because an ideal
output (both format and output device) depend on an application. It
should be passed a raised exception.
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-30689

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (regularfry)
on 2012-10-15 11:20
(Received via mailing list)
On 15/10/12 03:24, kosaki (Motohiro KOSAKI) wrote:
>
> Issue #6647 has been updated by kosaki (Motohiro KOSAKI).
>
>
> I think "exception raised" callback is better way because an ideal output (both
format and output device) depend on an application. It should be passed a raised
exception.

This, along with a sensible default that displays *something* to stderr,
would be absolutely ideal from my point of view.

--
Alex
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-10-17 20:00
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


I started prototyping a callback version and ran into some complexities
I could not easily resolve:

* How does abort_on_exception= interact with a callback system?
** I tried implementing abort_on_exception=true to use a builtin
callback that raises in Thread.main, but should abort_on_exception=true
blow away a previously-set callback?
** Similarly: should abort_on_exception=false reset to a do-nothing
callback?
** If neither of these, how do we combine callback and
abort_on_exception behavior?
* Seems like there should be a Thread.default_exception_handler you can
set once for all future threads.

My concern is that bikeshedding a callback API -- as useful as it might
be -- will cause further delays in the more important behavior of having
threads report that they terminated due to an exception.
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-30979

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
25db99905790a600f7fd2d67191fc542?d=identicon&s=25 dafiku (dafi harisy) (Guest)
on 2012-10-23 07:24
(Received via mailing list)
Issue #6647 has been updated by dafiku (dafi harisy).


Everlastingly, an issue with the intention of I am passionate in this
vicinity. I be inflicted with looked for in rank of this feature for the
last numerous hours. Your locate is greatly valued.
http://www.yourhousecontents.com/
http://www.electroscanogram.com/
http://www.videophototravel.info/
http://www.supershinelaundry.com/
http://www.ywor.info/
http://www.bicity.info/
http://www.ubidyne.info/
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-31313

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-11-16 16:40
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


Ping!
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-32967

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-11-24 18:20
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


Checking in on this again. Can we at least agree it should happen for
2.0.0? Perhaps Matz should review this?
----------------------------------------
Bug #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-33822

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: head


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2012-11-25 01:48
(Received via mailing list)
Issue #6647 has been updated by mame (Yusuke Endoh).

Target version changed from 2.0.0 to next minor


----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-33832

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-27 13:19
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


So, can we do this for 2.1? I have heard from many other users that
really would like exceptions bubbling out of threads to be reported in
some way. We have had numerous bug reports relating to code where
threads disappear without a trace.
----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42043

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
4dea430d31b993abaf41cd9b54f8128d?d=identicon&s=25 Avdi Grimm (avdi)
on 2013-09-30 00:35
(Received via mailing list)
This would indeed eliminate a huge amount of confusion for people
getting
started with threads. Or for people years of experience with threads,
for
that matter...


On Fri, Sep 27, 2013 at 7:18 AM, headius (Charles Nutter) <
headius@headius.com> wrote:

> https://bugs.ruby-lang.org/issues/6647#change-42043
> Ruby's behavior of quietly swallowing exceptions raised in threads. I
>
> Thread.current.abort_on_exception
>
>   thread_error.rb:7:in `new'
>
--
Avdi Grimm
http://avdi.org

I only check email twice a day. to reach me sooner, go to
http://awayfind.com/avdi
308cbef6e86dfc49cce3b2d4cf42aedc?d=identicon&s=25 SASADA Koichi (Guest)
on 2013-09-30 05:19
(Received via mailing list)
(2013/09/27 20:18), headius (Charles Nutter) wrote:
> So, can we do this for 2.1? I have heard from many other users that really would
like exceptions bubbling out of threads to be reported in some way. We have had
numerous bug reports relating to code where threads disappear without a trace.

I'll ask matz.

Does JRuby log it already?
Any problem on your experience if you have?
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 ko1 (Koichi Sasada) (Guest)
on 2013-09-30 05:20
(Received via mailing list)
Issue #6647 has been updated by ko1 (Koichi Sasada).

Target version changed from next minor to current: 2.1.0


----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42087

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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-30 16:06
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


We do not currently log it, but the patch to do so is trivial.

https://gist.github.com/6764310

I'm running tests now to confirm it doesn't break anything.
----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42106

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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-30 16:37
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


Testing seems to indicate this is a pretty safe change, and it just
makes the debug-logged exception output be logged any time
abort_on_exception is not true.
----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42107

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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 akr (Akira Tanaka) (Guest)
on 2013-10-02 04:05
(Received via mailing list)
Issue #6647 has been updated by akr (Akira Tanaka).


In the yesterday's meeting,
https://bugs.ruby-lang.org/projects/ruby/wiki/Deve...
we discussed this issue.

We found that message at thread exiting with exception have a problem.
The thread can be joined after exit and the exception may be handled by
joined thread.

% ruby -e '
t = Thread.new {
  raise "foo"
}
sleep 1 # the thread exits with an exception.
begin
  t.join
rescue
  p $! # something to do with the exception
end
'
#<RuntimeError: foo>

If thread exiting with exception outputs a message,
there is no way to disable to it.

So, the message should be delayed until Ruby is certain that
the thread is not joined.
This means the message should be output at the thread is collected by
GC.

----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42191

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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-02 07:30
(Received via mailing list)
Issue #6647 has been updated by headius (Charles Nutter).


akr (Akira Tanaka) wrote:
> In the yesterday's meeting,
> https://bugs.ruby-lang.org/projects/ruby/wiki/Deve...
> we discussed this issue.
>
> We found that message at thread exiting with exception have a problem.
> The thread can be joined after exit and the exception may be handled by joined
thread.
...
> If thread exiting with exception outputs a message,
> there is no way to disable to it.
>
> So, the message should be delayed until Ruby is certain that
> the thread is not joined.
> This means the message should be output at the thread is collected by GC.

GC is a pretty fuzzy time boundary, but it's not terrible. Handling it
will mean some finalization requirement for threads to say "hey, I just
GCed this thread that died due to an unhandled exception". I feel like
something more explicit is needed.

I guess I need to think about this. Some of the cases I want to fix --
where threads are spun up and left to do their own work -- this might be
acceptable. But many users will keep references to worker threads they
start in order to explicitly stop them on shutdown or other events. In
those cases, the thread will be hard referenced and never GCed...and
there will be no indication that the thread has died.

Perhaps this could be an on-by-default flag? It would require very
little work to add something like:

class Thread
  def report_on_exception=(report) ..
end

...where the default is true. Going forward, this would be like having
the debug output of a thread-killing exception always happen, but you
could turn it off. That would address your concern about not being able
to silence it.

The workflow would go like this:

If you are spinning up a thread to do background work and don't plan to
check on it...

* Spin up the thread
* Store it in a list if you like
* A message will be reported if the thread dies in an exceptional way

If you are spinning up a thread you plan to join on at some time in the
future...

* Spin up the thread
* Set Thread#report_on_exception = false
* Join at your leisure...no message will be reported

This at least allows users to say "I mean to pick up this thread's
results later...don't report an error" without having hard-referenced
threads die silently.

Is this a reasonable compromise?
----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42200

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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 ko1 (Koichi Sasada) (Guest)
on 2013-10-02 10:06
(Received via mailing list)
Issue #6647 has been updated by ko1 (Koichi Sasada).


FYT:
On pthread, there is pthread_detach() which declares nobody join on this
thread.
In other words, pthread_detach() is same as
Thread#report_on_exception=true.

----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42208

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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 ko1 (Koichi Sasada) (Guest)
on 2013-10-02 10:13
(Received via mailing list)
Issue #6647 has been updated by ko1 (Koichi Sasada).


Sorry, it is not same, but we can consier that.

BTW, I think it true as default is good idea.

IMO, inter-thread communication via exception with Thread#join should be
bad idea.

----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-42209

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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-02 21:39
(Received via mailing list)
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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
Eabad423977cfc6873b8f5df62b848a6?d=identicon&s=25 unknown (Guest)
on 2014-01-30 07:18
(Received via mailing list)
Issue #6647 has been updated by Hiroshi SHIBATA.

Target version changed from 2.1.0 to current: 2.2.0

----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-44745

* Author: Charles Nutter
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: current: 2.2.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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
308cbef6e86dfc49cce3b2d4cf42aedc?d=identicon&s=25 unknown (Guest)
on 2014-01-31 08:24
(Received via mailing list)
Issue #6647 has been updated by Koichi Sasada.


Restart for 2.2.
Matz, do you have any idea?


----------------------------------------
Feature #6647: Exceptions raised in threads should be logged
https://bugs.ruby-lang.org/issues/6647#change-44853

* Author: Charles Nutter
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: current: 2.2.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 #<Proc:0x000000010d008a80@thread_error.rb:17>
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
This topic is locked and can not be replied to.