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

Fix inifite loop cyclic nested exceptions #172

Merged
merged 2 commits into from
Nov 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rollbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,11 @@ def trace_data(exception)

def trace_chain(exception)
traces = [trace_data(exception)]
visited = [exception]

while exception.respond_to?(:cause) && (cause = exception.cause)
while exception.respond_to?(:cause) && (cause = exception.cause) && !visited.include?(cause)
traces << trace_data(cause)
visited << cause
exception = cause
end

Expand Down
34 changes: 26 additions & 8 deletions spec/rollbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,38 @@
chain[1][:exception][:message].should match(/the cause/)
end

context 'using ruby <= 2.1' do
next if Exception.instance_methods.include?(:cause)
context 'with cyclic nested exceptions' do
let(:exception1) { Exception.new('exception1') }
let(:exception2) { Exception.new('exception2') }

it 'sends only the last exception in the trace attribute' do
body = notifier.send(:build_payload_body_exception, message, rescued_exception, extra)
before do
allow(exception1).to receive(:cause).and_return(exception2)
allow(exception2).to receive(:cause).and_return(exception1)
end

body[:trace].should be_kind_of(Hash)
body[:trace_chain].should be_nil
it 'doesnt loop for ever' do
body = notifier.send(:build_payload_body_exception, message, exception1, extra)
chain = body[:trace_chain]

body[:trace][:exception][:class].should match(/StandardError/)
body[:trace][:exception][:message].should match(/the error/)
expect(chain[0][:exception][:message]).to be_eql('exception1')
expect(chain[1][:exception][:message]).to be_eql('exception2')
end
end
end

context 'using ruby <= 2.1' do
next if Exception.instance_methods.include?(:cause)

it 'sends only the last exception in the trace attribute' do
body = notifier.send(:build_payload_body_exception, message, rescued_exception, extra)

body[:trace].should be_kind_of(Hash)
body[:trace_chain].should be_nil

body[:trace][:exception][:class].should match(/StandardError/)
body[:trace][:exception][:message].should match(/the error/)
end
end
end
end

Expand Down