Sending after request end doesn't throw error, hangs response instead
See original GitHub issueHi, I’ve noticed that when including express-session
, the res.end
behavior (from what I’m assuming is due to the proxied res.end) deviates from what I would expect in handling errors.
Generally if I were to call res.end
and then later inadvertently call res.send
after that (perhaps in another middleware handler), I would receive an ERR_HTTP_HEADERS_SENT
. That’s what I was expecting to see—however, instead, if I include the session middleware, the headers send but it waits for 5s (which I think is the default keepAlive timeout) until erroring out with a content length mismatch (since it is setting Content-Length
but the body doesn’t go through). In my opinion, it would be helpful to have that original error bubble through if possible, since it was not clear that including this middleware would cause this API change to res.end
as a side effect.
var express = require("express");
var app = express();
// Uncommenting the middleware usage leads to different functionality in handling the duplicate response sending
app.use(
require("express-session")({
secret: "keyboard cat",
resave: true,
saveUninitialized: true,
})
);
app.get("/", function (req, res) {
res.end();
// Doesn't throw error! Waits for keepAlive duration
res.send("This is a test!");
});
app.listen(5000);
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Hi @josh-byster there is a PR #767 that should fix it if you are interested in giving it a test.
Completely understandable, and thank you for the clarification 😃 I just wanted to give an example of a concrete use case in addition, as I realized my original issue report lacked a concrete way for which this behavior may surface.