Package + Version
Version:
Description
This affects a complicated setup that I can't provide reproduction for easily.
The setup is:
- and express backend with
express-session middleware running
- custom session store that retrieves and stores session in a DynamoDB database and uses
AmazonDaxClient for DB operations
Steps are:
- navigate to express route that just returns some data
res.json('OK')
- The
express-middleware reads the session before handling the route and tries to save it on res.end() (which express-session wraps)
- When the saving of the session fails the dax client emits an
error event:

- The emitted event seems to get handled by Sentry itself in the code linked below, resulting in the next
express middleware running, even though the previous one has already responded to the request:
|
} |
|
return function sentryRequestMiddleware( |
|
req: http.IncomingMessage, |
|
res: http.ServerResponse, |
|
next: (error?: any) => void, |
|
): void { |
|
if (options && options.flushTimeout && options.flushTimeout > 0) { |
|
// eslint-disable-next-line @typescript-eslint/unbound-method |
|
const _end = res.end; |
|
res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void { |
|
void flush(options.flushTimeout) |
|
.then(() => { |
|
_end.call(this, chunk, encoding, cb); |
|
}) |
|
.then(null, e => { |
|
logger.error(e); |
|
}); |
|
}; |
|
} |
|
const local = domain.create(); |
|
local.add(req); |
|
local.add(res); |
|
local.on('error', next); |
|
|
- The difference with and without Sentry is that
this.domain is not defined in the code below when Sentry is not used

When the issue triggers then we are getting the ERR_HTTP_HEADERS_SENT error from Node because some later error middleware runs even though we've responded already.
Package + Version
@sentry/browser@sentry/noderaven-jsraven-node(raven for node)Version:
Description
This affects a complicated setup that I can't provide reproduction for easily.
The setup is:
express-sessionmiddleware runningAmazonDaxClientfor DB operationsSteps are:
res.json('OK')express-middlewarereads the session before handling the route and tries to save it onres.end()(whichexpress-sessionwraps)errorevent:expressmiddleware running, even though the previous one has already responded to the request:sentry-javascript/packages/node/src/handlers.ts
Lines 393 to 416 in a79c097
this.domainis not defined in the code below when Sentry is not usedWhen the issue triggers then we are getting the
ERR_HTTP_HEADERS_SENTerror from Node because some later error middleware runs even though we've responded already.