Skip to content

Commit

Permalink
http: wait for pending responses in closeIdleConnections
Browse files Browse the repository at this point in the history
PR-URL: #43890
Fixes: #43771
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
  • Loading branch information
ShogunPanda authored and danielleadams committed Jul 26, 2022
1 parent 9f9d00c commit 9c699bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ Server.prototype.closeIdleConnections = function() {
const connections = this[kConnections].idle();

for (let i = 0, l = connections.length; i < l; i++) {
if (connections[i].socket._httpMessage && !connections[i].socket._httpMessage.finished) {
continue;
}

connections[i].socket.destroy();
}
};
Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-http-server-close-idle-wait-response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const common = require('../common');

const { createServer, get } = require('http');

const server = createServer(common.mustCall(function(req, res) {
req.resume();

setTimeout(common.mustCall(() => {
res.writeHead(204, { 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=1' });
res.end();
}), common.platformTimeout(1000));
}));

server.listen(0, function() {
const port = server.address().port;

get(`http://localhost:${port}`, common.mustCall((res) => {
server.close();
})).on('finish', common.mustCall(() => {
setTimeout(common.mustCall(() => {
server.closeIdleConnections();
}), common.platformTimeout(500));
}));
});

0 comments on commit 9c699bd

Please sign in to comment.