Skip to content

Commit 700ffb1

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

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/node_http_parser.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ class Parser : public AsyncWrap, public StreamListener {
317317
num_fields_ = num_values_ = 0;
318318
headers_completed_ = false;
319319
chunk_extensions_nread_ = 0;
320+
received_data_ = true;
320321
last_message_start_ = uv_hrtime();
321322
allocator_.Reset();
322323
url_.Reset();
@@ -723,6 +724,7 @@ class Parser : public AsyncWrap, public StreamListener {
723724

724725
if (connectionsList != nullptr) {
725726
parser->connectionsList_ = connectionsList;
727+
parser->received_data_ = false;
726728

727729
// This protects from a DoS attack where an attacker establishes
728730
// the connection without sending any data on applications where
@@ -1064,6 +1066,7 @@ class Parser : public AsyncWrap, public StreamListener {
10641066
const char* current_buffer_data_;
10651067
bool headers_completed_ = false;
10661068
bool pending_pause_ = false;
1069+
bool received_data_ = false;
10671070
uint64_t header_nread_ = 0;
10681071
uint64_t chunk_extensions_nread_ = 0;
10691072
uint64_t max_http_header_size_;
@@ -1144,7 +1147,7 @@ void ConnectionsList::Idle(const FunctionCallbackInfo<Value>& args) {
11441147
LocalVector<Value> result(isolate);
11451148
result.reserve(list->all_connections_.size());
11461149
for (auto parser : list->all_connections_) {
1147-
if (parser->last_message_start_ == 0) {
1150+
if (parser->last_message_start_ == 0 || !parser->received_data_) {
11481151
result.emplace_back(parser->object());
11491152
}
11501153
}
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)