Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Prevent MultipleExceptionError#add from allowing self to be added to the list of all_exceptions #2133

Conversation

fables-tales
Copy link
Member

This was exposed by #2112 which
contains a spec which uses describe_successfully which seems to somehow
add the existing MultipleExceptionError to itself when it fails. This
does not happen if the example passes (presumably because an error
is not generated).

When we format the exception
here
we use FlatMap, which is going to continuously unpack the exception,
causing infinite recursion.

This patch prevents MultipleExceptionError::InterfaceTag#add from
allowing self to be included in the all_exceptions array. This fixes
the problem.

As far as I can tell from running our suite, the self being added case
never actually happens during normal RSpec execution and so adding this
is fine. I added a spec which demonstrates this behaviour in case that
turns out to be problematic in the future. I can't imagine that
happening though as this will precisely cause the same infinite
recursion bug.

…o the list of `all_exceptions`

This was exposed by #2112 which
contains a spec which uses `describe_successfully` which seems to somehow
add the existing `MultipleExceptionError` to itself when it fails. This
**does not happen** if the example passes (presumably because an error
is not generated).

When we format the exception
[here](https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/exception_presenter.rb#L330)
we use FlatMap, which is going to continuously unpack the exception,
causing infinite recursion.

This patch prevents `MultipleExceptionError::InterfaceTag#add` from
allowing `self` to be included in the `all_exceptions` array. This fixes
the problem.

As far as I can tell from running our suite, the `self` being added case
never actually happens during normal RSpec execution and so adding this
is fine. I added a spec which demonstrates this behaviour in case that
turns out to be problematic in the future. I can't imagine that
happening though as this will precisely cause the same infinite
recursion bug.
@fables-tales fables-tales force-pushed the samphippen/fix-multiple-exception-error-infinite-recursion branch from 749c829 to da560d7 Compare December 14, 2015 13:17
@soulcutter
Copy link
Member

LGTM - whenever CI finishes :shipit:

@fables-tales
Copy link
Member Author

@soulcutter thanks for the review! I'd really like to get @myronmarston's eyes on this before I merge, but I'm otherwise happy with this.

@soulcutter
Copy link
Member

Sounds good. The only thing I'm pondering is if there's a way to avoid this entirely.

@myronmarston
Copy link
Member

LGTM

fables-tales pushed a commit that referenced this pull request Dec 14, 2015
…-error-infinite-recursion

Prevent `MultipleExceptionError#add` from allowing self to be added to the list of `all_exceptions`
@fables-tales fables-tales merged commit 02d759c into master Dec 14, 2015
@fables-tales fables-tales deleted the samphippen/fix-multiple-exception-error-infinite-recursion branch December 14, 2015 16:10
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
…ption-error-infinite-recursion

Prevent `MultipleExceptionError#add` from allowing self to be added to the list of `all_exceptions`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants