GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: close pre-request sockets in closeIdleConnections · nodejs/node@417aacb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_http_parser.cc
  • test/parallel
    • test-http-server-close-idle-connections-pre-request.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_http_parser.cc‎

Copy file name to clipboardExpand all lines: src/node_http_parser.cc
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class Parser : public AsyncWrap, public StreamListener {
318318
num_fields_ = num_values_ = 0;
319319
headers_completed_ = false;
320320
chunk_extensions_nread_ = 0;
321+
received_data_ = true;
321322
last_message_start_ = uv_hrtime();
322323
allocator_.Reset();
323324
url_.Reset();
@@ -724,6 +725,7 @@ class Parser : public AsyncWrap, public StreamListener {
724725

725726
if (connectionsList != nullptr) {
726727
parser->connectionsList_ = connectionsList;
728+
parser->received_data_ = false;
727729

728730
// This protects from a DoS attack where an attacker establishes
729731
// the connection without sending any data on applications where
@@ -1070,6 +1072,7 @@ class Parser : public AsyncWrap, public StreamListener {
10701072
const char* current_buffer_data_;
10711073
bool headers_completed_ = false;
10721074
bool pending_pause_ = false;
1075+
bool received_data_ = false;
10731076
uint64_t header_nread_ = 0;
10741077
uint64_t chunk_extensions_nread_ = 0;
10751078
uint64_t max_http_header_size_;
@@ -1150,7 +1153,7 @@ void ConnectionsList::Idle(const FunctionCallbackInfo<Value>& args) {
11501153
LocalVector<Value> result(isolate);
11511154
result.reserve(list->all_connections_.size());
11521155
for (auto parser : list->all_connections_) {
1153-
if (parser->last_message_start_ == 0) {
1156+
if (parser->last_message_start_ == 0 || !parser->received_data_) {
11541157
result.emplace_back(parser->object());
11551158
}
11561159
}
Collapse file

‎test/parallel/test-http-server-close-idle-connections-pre-request.js‎

Copy file name to clipboard
+23Lines 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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.