Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite recursion when displaying an exception cause #272

Closed
cbandy opened this issue May 1, 2014 · 0 comments
Closed

Infinite recursion when displaying an exception cause #272

cbandy opened this issue May 1, 2014 · 0 comments

Comments

@cbandy
Copy link

cbandy commented May 1, 2014

It is possible for two exceptions to refer to each other as their cause, resulting in infinite recursion in display_exception_details. Here is a snippet that demonstrates the case:

irb(main):001:0> begin
irb(main):002:1*   begin
irb(main):003:2*     require 'nope_a'
irb(main):004:2>   rescue LoadError => e
irb(main):005:2>     begin
irb(main):006:3*       require 'nope_b'
irb(main):007:3>     rescue LoadError
irb(main):008:3>       raise e
irb(main):009:3>     end
irb(main):010:2>   end
irb(main):011:1> rescue Exception => f
irb(main):012:1>   a = f
irb(main):013:1> end
=> #<LoadError: cannot load such file -- nope_a>
irb(main):014:0> a.cause
=> #<LoadError: cannot load such file -- nope_b>
irb(main):015:0> a.cause.cause
=> #<LoadError: cannot load such file -- nope_a>
irb(main):016:0> a.cause.cause.cause
=> #<LoadError: cannot load such file -- nope_b>
irb(main):017:0> a.cause.cause.cause.cause
=> #<LoadError: cannot load such file -- nope_a>

I discovered this while using Sequel in a Rake task. That gem uses this construct to load drivers in a particular order and raise the preferred driver when all fail. I'm going to recommend a change over in that project, but this was so easy to replicate, I thought Rake may need to guard against it as well.

drbrain added a commit that referenced this issue May 13, 2014
drbrain added a commit that referenced this issue May 13, 2014
@drbrain drbrain added this to the 10.4 milestone May 13, 2014
nobu added a commit to nobu/rake that referenced this issue Jan 4, 2017
As the result of https://bugs.ruby-lang.org/issues/13043, now
Exception#cause should not have a loop.

In the example jimweirich#272, the
code doesn't seem to intend the loop itself but just re-raising
the first exception instead of the next exception.  Therefore I
consider the last assertion superfluous.
aycabta pushed a commit to aycabta/rake that referenced this issue Jan 23, 2017
As the result of https://bugs.ruby-lang.org/issues/13043, now
Exception#cause should not have a loop.

In the example jimweirich#272, the
code doesn't seem to intend the loop itself but just re-raising
the first exception instead of the next exception.  Therefore I
consider the last assertion superfluous.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants