Skip to content

Commit

Permalink
http: response should always emit 'close'
Browse files Browse the repository at this point in the history
Fixes: #40528

PR-URL: #40543
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
ronag authored and nodejs-github-bot committed Oct 25, 2021
1 parent 070b54a commit 3b9044b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-http-response-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
})
);
}

0 comments on commit 3b9044b

Please sign in to comment.