Skip to content

Commit d807464

Browse files
committed
http: close pre-request sockets in closeIdleConnections
Signed-off-by: semimikoh <ejffjeosms@gmail.com>
1 parent b0e1f2c commit d807464

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/_http_server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ Server.prototype.closeIdleConnections = function closeIdleConnections() {
681681
}
682682

683683
const connections = this[kConnections].idle();
684+
const allConnections = this[kConnections].all();
684685

685686
for (let i = 0, l = connections.length; i < l; i++) {
686687
if (connections[i].socket._httpMessage && !connections[i].socket._httpMessage.finished) {
@@ -689,6 +690,12 @@ Server.prototype.closeIdleConnections = function closeIdleConnections() {
689690

690691
connections[i].socket.destroy();
691692
}
693+
694+
for (let i = 0, l = allConnections.length; i < l; i++) {
695+
if (allConnections[i].socket.bytesRead === 0) {
696+
allConnections[i].socket.destroy();
697+
}
698+
}
692699
};
693700

694701
Server.prototype.setTimeout = function setTimeout(msecs, callback) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const { createServer } = require('http');
6+
const { createConnection } = require('net');
7+
8+
const server = createServer(common.mustNotCall());
9+
10+
server.listen(0, '127.0.0.1', common.mustCall(() => {
11+
const port = server.address().port;
12+
server.once('connection', common.mustCall(() => {
13+
server.close(common.mustCall());
14+
server.closeIdleConnections();
15+
setTimeout(common.mustNotCall(), common.platformTimeout(1000)).unref();
16+
}));
17+
18+
const socket = createConnection(port, '127.0.0.1');
19+
20+
socket.on('connect', common.mustCall());
21+
socket.on('close', common.mustCall());
22+
socket.on('error', () => {});
23+
}));

0 commit comments

Comments
 (0)