Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1936,9 +1936,13 @@ value only affects new connections to the server, not any existing connections.

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

* 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
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-http-keep-alive-max-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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 = '';

Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-http-keep-alive-pipeline-max-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();
Expand Down