Skip to content

Commit 7c6ad38

Browse files
committed
Increase default keepAliveTimeout to 60s and warn on legacy 5s usage
1 parent d5b815c commit 7c6ad38

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

doc/api/http.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,9 @@ added: v8.0.0
19401940

19411941
* Type: {number} Timeout in milliseconds. **Default:** `5000` (5 seconds).
19421942

1943+
> **Note:** As of Node.js v24.0.0, the default value for `http.Server.keepAliveTimeout` is **60000ms (60s)**. Previous versions used **5000ms (5s)**. This aligns Node.js with browsers, proxies, and mobile clients, and avoids subtle connection failures. If your infrastructure expects the old value, set it explicitly. See [issue #59193](https://github.com/nodejs/node/issues/59193).
1944+
1945+
19431946
The number of milliseconds of inactivity a server needs to wait for additional
19441947
incoming data, after it has finished writing the last response, before a socket
19451948
will be destroyed. If the server receives new data before the keep-alive

doc/changelogs/CHANGELOG_V24.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ latest release and evaluate their potential impact on your applications.
624624
625625
## Notable Changes
626626
627+
### Breaking Changes
628+
- **http:** Changed the default value of `http.Server.keepAliveTimeout` from **5000ms (5s)** to **60000ms (60s)**. This prevents subtle long-connection failures due to premature socket closure, aligning with industry norms (browsers, proxies, mobile clients). See [issue #59193](https://github.com/nodejs/node/issues/59193).
629+
630+
627631
### V8 13.6
628632
629633
The V8 engine is updated to version 13.6, which includes several new

lib/_http_server.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,24 @@ function storeHTTPOptions(options) {
478478

479479
const keepAliveTimeout = options.keepAliveTimeout;
480480
if (keepAliveTimeout !== undefined) {
481-
validateInteger(keepAliveTimeout, 'keepAliveTimeout', 0);
482-
this.keepAliveTimeout = keepAliveTimeout;
481+
validateInteger(keepAliveTimeout, 'keepAliveTimeout', 0);
482+
this.keepAliveTimeout = keepAliveTimeout;
483+
if (keepAliveTimeout === 5000) {
484+
process.emitWarning(
485+
'You are explicitly setting http.Server.keepAliveTimeout to 5000ms (5s), which was the legacy default. ' +
486+
'This value is shorter than most industry infrastructure expects and can cause subtle connection failures. ' +
487+
'It is recommended to use a higher value, such as 60000ms (60s). See: https://github.com/nodejs/node/issues/59193',
488+
{ code: 'LEGACY_KEEPALIVETIMEOUT', detail: 'Consider increasing the value to match common proxy/browser defaults.' }
489+
);
490+
}
483491
} else {
484-
this.keepAliveTimeout = 5_000; // 5 seconds;
492+
this.keepAliveTimeout = 60_000; // 60 seconds
493+
process.emitWarning(
494+
'The default http.Server.keepAliveTimeout has changed from 5000ms (5s) to 60000ms (60s) in Node.js v24.0.0. ' +
495+
'This change aligns Node.js with common proxy and browser expectations and prevents subtle long-lived connection failures. ' +
496+
'If your application relies on the previous default, set it explicitly. See: https://github.com/nodejs/node/issues/59193',
497+
{ code: 'KEEPALIVETIMEOUT_DEFAULT_CHANGED', detail: 'Check your infrastructure and client expectations.' }
498+
);
485499
}
486500

487501
const connectionsCheckingInterval = options.connectionsCheckingInterval;

0 commit comments

Comments
 (0)