Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ Server.prototype.closeIdleConnections = function closeIdleConnections() {
}

const connections = this[kConnections].idle();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach does look like it works fine, but I wonder if it's changing the wrong level. Could we just make idle() return these connections as well? That would be clearer, and avoid hitting the same issue if we use idle() anywhere else.

I think this is fairly doable: I'd suggest adding a boolean field like received_data_ in the parser, set to false in Initalize, and then true in on_message_begin. Single boolean & write, so very cheap, and then ConnectionsList::Idle can return any connections where it's still false.

What do you think?

const allConnections = this[kConnections].all();

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

connections[i].socket.destroy();
}

for (let i = 0, l = allConnections.length; i < l; i++) {
if (allConnections[i].socket.bytesRead === 0) {
allConnections[i].socket.destroy();
}
}
};

Server.prototype.setTimeout = function setTimeout(msecs, callback) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

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

const { createServer } = require('http');
const { createConnection } = require('net');

const server = createServer(common.mustNotCall());

server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = server.address().port;
server.once('connection', common.mustCall(() => {
server.close(common.mustCall());
server.closeIdleConnections();
setTimeout(common.mustNotCall(), common.platformTimeout(1000)).unref();
}));

const socket = createConnection(port, '127.0.0.1');

socket.on('connect', common.mustCall());
socket.on('close', common.mustCall());
socket.on('error', () => {});
}));
Loading