You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are using Fastify and have configured Sentry using a plugin:
const sentryPlugin = fastifyPlugin(async (instance) => {
instance.addHook('onRequest', (request, reply, done) => {
const currentHub = getCurrentHub();
currentHub.pushScope();
currentHub.configureScope((scope) => {
scope.addEventProcessor((event) => {
return addRequestDataToEvent(event, request.raw);
});
// additional context set on the scope
// including setting the user
})
done();
});
instance.addHook('onResponse', (request, reply, done) => {
const currentHub = getCurrentHub();
currentHub.popScope();
done();
});
If we just fire off a few requests, this all works as expected -- the event in Sentry is decorated with the correct context and user. But if we spam the server, we can see the scope leaking and the event showing the wrong user.
As far as we can tell, we're calling popScope each time we call pushScope. Is there anything else that could explain this behavior?
Expected Result
When calling any SDK method like captureException, the correct scope would be used after calling pushScope.
Actual Result
Sporadically, the wrong scope is used.
The text was updated successfully, but these errors were encountered:
But if we spam the server, we can see the scope leaking and the event showing the wrong user
Yes, this is because the operations are async. Therefore, when you call popScope, you might be popping the wrong scope off the stack. In these situations, we recommend storing the scope with async hooks, or using domains as is noted in #4784 (comment)
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/node
SDK Version
7.14.0
Framework Version
Node 16.15.1
Link to Sentry event
No response
Steps to Reproduce
We are using Fastify and have configured Sentry using a plugin:
If we just fire off a few requests, this all works as expected -- the event in Sentry is decorated with the correct context and user. But if we spam the server, we can see the scope leaking and the event showing the wrong user.
As far as we can tell, we're calling
popScope
each time we callpushScope
. Is there anything else that could explain this behavior?Expected Result
When calling any SDK method like
captureException
, the correct scope would be used after callingpushScope
.Actual Result
Sporadically, the wrong scope is used.
The text was updated successfully, but these errors were encountered: