From b33c71675617676b2830cda30c8619155b5cb44a Mon Sep 17 00:00:00 2001 From: Prashant Bansal <129582877+pras529@users.noreply.github.com> Date: Fri, 25 Jul 2025 03:34:04 +0000 Subject: [PATCH 1/2] http: increase keepAliveTimeout default Increase the default keepAliveTimeout to 65 seconds in the http module. Tests have been updated to explicitly set the new timeout value. PR-URL: https://github.com/nodejs/node/pull/59203 --- doc/api/http.md | 6 +++++- lib/_http_server.js | 2 +- test/parallel/test-http-keep-alive-max-requests.js | 7 +++++-- .../parallel/test-http-keep-alive-pipeline-max-requests.js | 7 ++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index af7a1218734793..b78cf2d5499dd6 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1936,9 +1936,13 @@ value only affects new connections to the server, not any existing connections. -* Type: {number} Timeout in milliseconds. **Default:** `5000` (5 seconds). +* Type: {number} Timeout in milliseconds. **Default:** `65000` (65 seconds). The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket diff --git a/lib/_http_server.js b/lib/_http_server.js index dd743baa306183..2d9557486ed742 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -481,7 +481,7 @@ function storeHTTPOptions(options) { validateInteger(keepAliveTimeout, 'keepAliveTimeout', 0); this.keepAliveTimeout = keepAliveTimeout; } else { - this.keepAliveTimeout = 5_000; // 5 seconds; + this.keepAliveTimeout = 65_000; // 65 seconds; } const connectionsCheckingInterval = options.connectionsCheckingInterval; diff --git a/test/parallel/test-http-keep-alive-max-requests.js b/test/parallel/test-http-keep-alive-max-requests.js index 0516a06da651d7..1d240e5710ec73 100644 --- a/test/parallel/test-http-keep-alive-max-requests.js +++ b/test/parallel/test-http-keep-alive-max-requests.js @@ -10,11 +10,11 @@ const bodySent = 'This is my request'; function assertResponse(headers, body, expectClosed) { if (expectClosed) { assert.match(headers, /Connection: close\r\n/m); - assert.strictEqual(headers.search(/Keep-Alive: timeout=5\r\n/m), -1); + assert.strictEqual(headers.search(/Keep-Alive: timeout=65\r\n/m), -1); assert.match(body, /Hello World!/m); } else { assert.match(headers, /Connection: keep-alive\r\n/m); - assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m); + assert.match(headers, /Keep-Alive: timeout=65, max=3\r\n/m); assert.match(body, /Hello World!/m); } } @@ -52,6 +52,9 @@ const server = http.createServer((req, res) => { }); }); +server.keepAliveTimeout = 65 * 1000; // 65 seconds +server.maxRequestsPerSocket = 3; + function initialRequests(socket, numberOfRequests, cb) { let buffer = ''; diff --git a/test/parallel/test-http-keep-alive-pipeline-max-requests.js b/test/parallel/test-http-keep-alive-pipeline-max-requests.js index 6a07eb2638c86f..5925228d5c96fa 100644 --- a/test/parallel/test-http-keep-alive-pipeline-max-requests.js +++ b/test/parallel/test-http-keep-alive-pipeline-max-requests.js @@ -10,11 +10,11 @@ const bodySent = 'This is my request'; function assertResponse(headers, body, expectClosed) { if (expectClosed) { assert.match(headers, /Connection: close\r\n/m); - assert.strictEqual(headers.search(/Keep-Alive: timeout=5, max=3\r\n/m), -1); + assert.strictEqual(headers.search(/Keep-Alive: timeout=65, max=3\r\n/m), -1); assert.match(body, /Hello World!/m); } else { assert.match(headers, /Connection: keep-alive\r\n/m); - assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m); + assert.match(headers, /Keep-Alive: timeout=65, max=3\r\n/m); assert.match(body, /Hello World!/m); } } @@ -46,6 +46,7 @@ const server = http.createServer((req, res) => { }); }); +server.keepAliveTimeout = 65 * 1000; // 65 seconds server.maxRequestsPerSocket = 3; server.listen(0, common.mustCall((res) => { @@ -76,7 +77,7 @@ server.listen(0, common.mustCall((res) => { assert.match(responseParts[6], /HTTP\/1\.1 503 Service Unavailable/m); assert.match(responseParts[6], /Connection: close\r\n/m); - assert.strictEqual(responseParts[6].search(/Keep-Alive: timeout=5\r\n/m), -1); + assert.strictEqual(responseParts[6].search(/Keep-Alive: timeout=65\r\n/m), -1); assert.strictEqual(responseParts[7].search(/Hello World!/m), -1); socket.end(); From 55e24f3011f86178cc051234a76ab50e29d18d09 Mon Sep 17 00:00:00 2001 From: Prashant Bansal <129582877+pras529@users.noreply.github.com> Date: Sat, 26 Jul 2025 14:30:23 +0000 Subject: [PATCH 2/2] doc: fix version change as suggested PR-URL: https://github.com/nodejs/node/pull/59203 --- doc/api/http.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index b78cf2d5499dd6..142b17f9ee449d 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1937,7 +1937,7 @@ value only affects new connections to the server, not any existing connections.