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 incorrect session handledCount when notifying in quick succession #434

Merged
merged 6 commits into from
Feb 27, 2019

Conversation

fractalwrench
Copy link
Contributor

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 if bugsnag.notify() was called twice, the session object handledCount 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

  • Updated Error.Builder (and calling code) to take a SessionTracker rather than Session (a lot of sites use this method, so it may be easier to inspect the PR by viewing individual commits)
  • Added copySession method which copies a Session object
  • Made incrementHandledError and incrementUnhandledError return a Session object which is a copy of SessionTracker#currentSession
  • Move incrementing of handled/unhandled counts from Client#notify to Error.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.

bugsnag.notify(err)
bugsnag.notify(err)

@fractalwrench fractalwrench merged commit 9403f00 into master Feb 27, 2019
@fractalwrench fractalwrench deleted the session-count-fix branch February 27, 2019 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants