Skip to content

Commit b33c716

Browse files
committed
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: #59203
1 parent d5b815c commit b33c716

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

doc/api/http.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,13 @@ value only affects new connections to the server, not any existing connections.
19361936

19371937
<!-- YAML
19381938
added: v8.0.0
1939+
changes:
1940+
- version: v24.0.0
1941+
pr-url: https://github.com/nodejs/node/pull/59203
1942+
description: the default value for `http.Server.keepAliveTimeout` is changed from 5 to 65 seconds.
19391943
-->
19401944

1941-
* Type: {number} Timeout in milliseconds. **Default:** `5000` (5 seconds).
1945+
* Type: {number} Timeout in milliseconds. **Default:** `65000` (65 seconds).
19421946

19431947
The number of milliseconds of inactivity a server needs to wait for additional
19441948
incoming data, after it has finished writing the last response, before a socket

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ function storeHTTPOptions(options) {
481481
validateInteger(keepAliveTimeout, 'keepAliveTimeout', 0);
482482
this.keepAliveTimeout = keepAliveTimeout;
483483
} else {
484-
this.keepAliveTimeout = 5_000; // 5 seconds;
484+
this.keepAliveTimeout = 65_000; // 65 seconds;
485485
}
486486

487487
const connectionsCheckingInterval = options.connectionsCheckingInterval;

test/parallel/test-http-keep-alive-max-requests.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const bodySent = 'This is my request';
1010
function assertResponse(headers, body, expectClosed) {
1111
if (expectClosed) {
1212
assert.match(headers, /Connection: close\r\n/m);
13-
assert.strictEqual(headers.search(/Keep-Alive: timeout=5\r\n/m), -1);
13+
assert.strictEqual(headers.search(/Keep-Alive: timeout=65\r\n/m), -1);
1414
assert.match(body, /Hello World!/m);
1515
} else {
1616
assert.match(headers, /Connection: keep-alive\r\n/m);
17-
assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m);
17+
assert.match(headers, /Keep-Alive: timeout=65, max=3\r\n/m);
1818
assert.match(body, /Hello World!/m);
1919
}
2020
}
@@ -52,6 +52,9 @@ const server = http.createServer((req, res) => {
5252
});
5353
});
5454

55+
server.keepAliveTimeout = 65 * 1000; // 65 seconds
56+
server.maxRequestsPerSocket = 3;
57+
5558
function initialRequests(socket, numberOfRequests, cb) {
5659
let buffer = '';
5760

test/parallel/test-http-keep-alive-pipeline-max-requests.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const bodySent = 'This is my request';
1010
function assertResponse(headers, body, expectClosed) {
1111
if (expectClosed) {
1212
assert.match(headers, /Connection: close\r\n/m);
13-
assert.strictEqual(headers.search(/Keep-Alive: timeout=5, max=3\r\n/m), -1);
13+
assert.strictEqual(headers.search(/Keep-Alive: timeout=65, max=3\r\n/m), -1);
1414
assert.match(body, /Hello World!/m);
1515
} else {
1616
assert.match(headers, /Connection: keep-alive\r\n/m);
17-
assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m);
17+
assert.match(headers, /Keep-Alive: timeout=65, max=3\r\n/m);
1818
assert.match(body, /Hello World!/m);
1919
}
2020
}
@@ -46,6 +46,7 @@ const server = http.createServer((req, res) => {
4646
});
4747
});
4848

49+
server.keepAliveTimeout = 65 * 1000; // 65 seconds
4950
server.maxRequestsPerSocket = 3;
5051

5152
server.listen(0, common.mustCall((res) => {
@@ -76,7 +77,7 @@ server.listen(0, common.mustCall((res) => {
7677

7778
assert.match(responseParts[6], /HTTP\/1\.1 503 Service Unavailable/m);
7879
assert.match(responseParts[6], /Connection: close\r\n/m);
79-
assert.strictEqual(responseParts[6].search(/Keep-Alive: timeout=5\r\n/m), -1);
80+
assert.strictEqual(responseParts[6].search(/Keep-Alive: timeout=65\r\n/m), -1);
8081
assert.strictEqual(responseParts[7].search(/Hello World!/m), -1);
8182

8283
socket.end();

0 commit comments

Comments
 (0)