Skip to content

Commit 825a683

Browse files
ronagtargos
authored andcommitted
http: response should always emit 'close'
Fixes: #40528 PR-URL: #40543 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent b320387 commit 825a683

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/_http_server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ function resOnFinish(req, res, socket, state, server) {
839839
}
840840

841841
function emitCloseNT(self) {
842-
if (!self.destroyed) {
842+
if (!self._closed) {
843843
self.destroyed = true;
844844
self._closed = true;
845845
self.emit('close');

test/parallel/test-http-response-close.js

+22
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,25 @@ const assert = require('assert');
7878
})
7979
);
8080
}
81+
82+
{
83+
const server = http.createServer(
84+
common.mustCall((req, res) => {
85+
res.on('close', common.mustCall());
86+
res.destroy();
87+
})
88+
);
89+
90+
server.listen(
91+
0,
92+
common.mustCall(() => {
93+
http.get(
94+
{ port: server.address().port },
95+
common.mustNotCall()
96+
)
97+
.on('error', common.mustCall(() => {
98+
server.close();
99+
}));
100+
})
101+
);
102+
}

0 commit comments

Comments
 (0)