diff --git a/doc/api/http.md b/doc/api/http.md index af7a1218734793..142b17f9ee449d 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();