Fix incorrect session handledCount when notifying in quick succession #434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
By default
bugsnag.notify()
captures error reports synchronously, then delivers them asynchronously. The delivery process serialises information about the current session into the error, including counts of handled/unhandled errors that have occurred in the session.These counts were serialised in the async delivery, from a shared
session
object reference. This meant ifbugsnag.notify()
was called twice, the session objecthandledCount
would be incremented twice, then serialised with the incorrect counts.This PR fixes this behaviour to ensure the counts are correct.
Design
A defensive copy has been made of the session object when populating the error field, meaning mutations made by other errors do not affect the state of other reports.
Changeset
Error.Builder
(and calling code) to take aSessionTracker
rather thanSession
(a lot of sites use this method, so it may be easier to inspect the PR by viewing individual commits)copySession
method which copies aSession
objectincrementHandledError
andincrementUnhandledError
return aSession
object which is a copy ofSessionTracker#currentSession
Client#notify
toError.Builder#build
, as this more accurately reflects where the error capture occurs.Tests
Added a unit test for copying sessions
This can be manually reproduced by notifying twice, and verifying that the
handledCount
equals 1 for one report, and 2 for the other report, rather than 2 for both.