Project

General

Profile

Actions

Bug #13043

closed

Exception#cause can become recursive/infinite

Added by ccutrer (Cody Cutrer) almost 8 years ago. Updated almost 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
[ruby-core:78688]

Description

In a certain situation, Exception#cause can become an infinite list:

def raise_errors
  begin
    raise "error 1"
  ensure
     orig_error = $!
     begin
       raise "error 2"
     rescue => err
       raise orig_error || err
     end
  end
end

x = nil
begin
  raise_errors
rescue
  x = $!
end

x.cause.cause.object_id == x.object_id

Note that this pattern happened during an HTTP request with net/http: see https://github.com/ruby/ruby/blob/v2_3_1/lib/net/http/response.rb#L261. I would expect that x would be "error 2", x.cause would be "error 1", and x.cause.cause would be nil. Instead an infinite loop forms, breaking error reporting code that loops over an exception's cause

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0