http: response should always emit 'close'

Fixes: https://github.com/nodejs/node/issues/40528

PR-URL: https://github.com/nodejs/node/pull/40543
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Robert Nagy authored and Node.js GitHub Bot committed 2021-10-25 07:35:24 +00:00
1 parent 070b54a4ac
commit 3b9044b5b2
2 files changed
+23 -1

No files matched your search

+1 -1
View File
@@ -839,7 +839,7 @@ function resOnFinish(req, res, socket, state, server) {
}
function emitCloseNT(self) {
if (!self.destroyed) {
if (!self._closed) {
self.destroyed = true;
self._closed = true;
self.emit('close');
+22
View File
@@ -78,3 +78,25 @@ const assert = require('assert');
})
);
}
{
const server = http.createServer(
common.mustCall((req, res) => {
res.on('close', common.mustCall());
res.destroy();
})
);
server.listen(
0,
common.mustCall(() => {
http.get(
{ port: server.address().port },
common.mustNotCall()
)
.on('error', common.mustCall(() => {
server.close();
}));
})
);
}