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 2021-10-21 11:41:22 +02:00 committed by Node.js GitHub Bot
parent 070b54a4ac
commit 3b9044b5b2
2 changed files with 23 additions and 1 deletions

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');

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();
}));
})
);
}