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

Express/Koa/Restify plugin adds new error callbacks on each request without removing old callbacks, resulting in the wrong request being reported and timeouts #1875

Closed
hansottowirtz opened this issue Nov 27, 2022 · 1 comment

Comments

@hansottowirtz
Copy link

hansottowirtz commented Nov 27, 2022

Describe the bug

These lines are run on every request in the express plugin:

const requestClient = client._config.autoTrackSessions ? client.resumeSession() : clone(client)
// attach it to the request
req.bugsnag = requestClient
// extract request info and pass it to the relevant bugsnag properties
requestClient.addOnError((event) => {
const { metadata, request } = getRequestAndMetadataFromReq(req)
event.request = { ...event.request, ...request }
requestClient.addMetadata('request', metadata)
}, true)

When autoTrackSessions: true (which is the default), the same requestClient is used as for previous requests. This means that a new callback is added to the error callbacks array on every request. This has the following consequences:

  • The wrong request is reported in the Request tab on Bugsnag (the body of the first request is always used, regardless of the request that caused the error)
  • After many requests, the Bugsnag flush times out (we think this is the reason)

Is it possible that old callbacks are not removed when they should be?

Steps to reproduce

I think any express/koa/restify app without autoTrackSessions: false will have this problem.

Environment

We're using the Express plugin together with the AWS Lambda plugin.

  • Bugsnag version: 7.17.0
@hansottowirtz hansottowirtz changed the title Express plugin adds new error callbacks without removing old callbacks, resulting in the wrong request being reported and timeouts Express/Koa/Restify plugin adds new error callbacks on each request without removing old callbacks, resulting in the wrong request being reported and timeouts Nov 27, 2022
djskinner added a commit that referenced this issue Nov 28, 2022
djskinner added a commit that referenced this issue Nov 28, 2022
djskinner added a commit that referenced this issue Nov 28, 2022
djskinner added a commit that referenced this issue Nov 28, 2022
djskinner added a commit that referenced this issue Nov 28, 2022
@luke-belton
Copy link
Member

Hi @hansottowirtz - the fix in #1887 for the issue you addressed in this PR has been released in https://github.com/bugsnag/bugsnag-js/releases/tag/v7.19.0. 🎉 Thanks for reporting this!

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

No branches or pull requests

2 participants