http: always emit close on req and res

PR-URL: https://github.com/nodejs/node/pull/20611
Fixes: https://github.com/nodejs/node/issues/20600
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Robert Nagy 2018-05-08 21:56:24 +02:00 committed by Trivikram Kamat
parent eafb30ccbf
commit f22c7c10ca
2 changed files with 18 additions and 0 deletions

View File

@ -561,6 +561,8 @@ function resOnFinish(req, res, socket, state, server) {
req._dump(); req._dump();
res.detachSocket(socket); res.detachSocket(socket);
req.emit('close');
res.emit('close');
if (res._last) { if (res._last) {
if (typeof socket.destroySoon === 'function') { if (typeof socket.destroySoon === 'function') {

View File

@ -0,0 +1,16 @@
'use strict';
const common = require('../common');
const http = require('http');
const server = http.Server(common.mustCall((req, res) => {
res.end();
res.on('finish', common.mustCall());
res.on('close', common.mustCall());
req.on('close', common.mustCall());
res.socket.on('close', () => server.close());
}));
server.listen(0, common.mustCall(() => {
http.get({ port: server.address().port }, common.mustCall());
}));