diff --git a/lib/_http_server.js b/lib/_http_server.js index 045e0b2f719..0d06919ea01 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -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'); diff --git a/test/parallel/test-http-response-close.js b/test/parallel/test-http-response-close.js index 0435cd0ee37..848d316d8ad 100644 --- a/test/parallel/test-http-response-close.js +++ b/test/parallel/test-http-response-close.js @@ -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(); + })); + }) + ); +}