Skip to content

Commit

Permalink
http: always emit close on req and res
Browse files Browse the repository at this point in the history
PR-URL: #20611
Fixes: #20600
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
ronag authored and trivikr committed May 13, 2018
1 parent eafb30c commit f22c7c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ function resOnFinish(req, res, socket, state, server) {
req._dump();

res.detachSocket(socket);
req.emit('close');
res.emit('close');

if (res._last) {
if (typeof socket.destroySoon === 'function') {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-http-req-res-close.js
Original file line number Diff line number Diff line change
@@ -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());
}));

0 comments on commit f22c7c1

Please sign in to comment.