-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
"Cannot set headers after they are sent to the client" (ERR_HTTP_HEADERS_SENT) with AmazonDaxClient #4566
Comments
Thanks for the detailed issue. Could you provide your I assume there's a conflict with domains here, but I'm not familiar enough with express middlewares to be certain. I'm putting this in our backlog to address, but PRs welcome for anyone who wants to help out! |
The Here is minimal reproduction that reproduces with minimal dummy |
I'm also getting the same error. I've used git-bisect to determine that the regression was introduced in 6.14.0 (6.13.3 works fine). |
@lobsterkatie Just confirming that the ongoing solution to this for affected users has been to downgrade to 6.13.3 |
Pushed this up in priority - in the mean time, PRs are welcome if any one wants to take a look and help us out! |
Getting the same error doesn't mean that the root issue is the same. This error can trigger for various reasons. I don't quite see how my specific issue could be fixed without maybe refactoring how things fundamentally work. |
I just tested your sentry-bug-repro example with 7.16.0 and since #5627, The output I get is:
|
@AbhiPrasad can probably confirm, but I think this is blocked on |
Can folks not explicitly catch and manage the error here? The issue with domain and |
It's happening in some third-party middleware. I suppose I can try and wrap our call to |
There is no way to do this unfortunately since
@rchl I changed your code to catch the error and pass it onto the callback like this, rather than allow an unhandledrejection: set(sid, data, cb) {
const request = new RequestObject();
new Promise((resolve) => {
// Delaying a bit to also trigger the ERR_HTTP_HEADERS_SENT error.
setTimeout(() => {
try {
request.emitError();
cb();
} catch (e) {
cb(e);
}
});
});
} With 7.16.0, I get the following output, even when NOT using the Sentry handler:
|
I've just tested it and the The assertion that So to fix your issue:
Please feel free to re-open this issue if you have any new information or you believe the above is not true. |
@timfish I think this alone fixes the whole issue:
I could discuss other points that you've raised but I think it's not really relevant given the above. Thanks for handling it. |
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
Description
This affects a complicated setup that I can't provide reproduction for easily.
The setup is:
express-session
middleware runningAmazonDaxClient
for DB operationsSteps are:
res.json('OK')
express-middleware
reads the session before handling the route and tries to save it onres.end()
(whichexpress-session
wraps)error
event:express
middleware 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.domain
is not defined in the code below when Sentry is not usedWhen 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.The text was updated successfully, but these errors were encountered: