Skip to content

Commit 9c699bd

Browse files
ShogunPandadanielleadams
authored andcommitted
http: wait for pending responses in closeIdleConnections
PR-URL: #43890 Fixes: #43771 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 9f9d00c commit 9c699bd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/_http_server.js

+4
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ Server.prototype.closeIdleConnections = function() {
494494
const connections = this[kConnections].idle();
495495

496496
for (let i = 0, l = connections.length; i < l; i++) {
497+
if (connections[i].socket._httpMessage && !connections[i].socket._httpMessage.finished) {
498+
continue;
499+
}
500+
497501
connections[i].socket.destroy();
498502
}
499503
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const { createServer, get } = require('http');
6+
7+
const server = createServer(common.mustCall(function(req, res) {
8+
req.resume();
9+
10+
setTimeout(common.mustCall(() => {
11+
res.writeHead(204, { 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=1' });
12+
res.end();
13+
}), common.platformTimeout(1000));
14+
}));
15+
16+
server.listen(0, function() {
17+
const port = server.address().port;
18+
19+
get(`http://localhost:${port}`, common.mustCall((res) => {
20+
server.close();
21+
})).on('finish', common.mustCall(() => {
22+
setTimeout(common.mustCall(() => {
23+
server.closeIdleConnections();
24+
}), common.platformTimeout(500));
25+
}));
26+
});

0 commit comments

Comments
 (0)