mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
http: wait for pending responses in closeIdleConnections
PR-URL: https://github.com/nodejs/node/pull/43890 Fixes: https://github.com/nodejs/node/issues/43771 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
1 parent
9f9d00ccbb
commit
9c699bd8a8
2 files changed
+30
No files matched your search
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
}));
|
||||
});
|
||||
Reference in new issue
Block a user