Skip to content

Commit 56e86bb

Browse files
committed
http2: initialize keepAliveTimeout and keepAliveTimeoutBuffer when allowHTTP1 is true
1 parent 3ab9dd8 commit 56e86bb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/internal/http2/core.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
ArrayIsArray,
66
MathMin,
77
Number,
8+
NumberIsFinite,
89
ObjectAssign,
910
ObjectDefineProperty,
1011
ObjectEntries,
@@ -3389,6 +3390,20 @@ class Http2SecureServer extends TLSServer {
33893390
this.headersTimeout = 60_000; // Minimum between 60 seconds or requestTimeout
33903391
this.requestTimeout = 300_000; // 5 minutes
33913392
this.connectionsCheckingInterval = 30_000; // 30 seconds
3393+
const keepAliveTimeout = options.keepAliveTimeout;
3394+
if (keepAliveTimeout !== undefined) {
3395+
validateInteger(keepAliveTimeout, 'keepAliveTimeout', 0);
3396+
this.keepAliveTimeout = keepAliveTimeout;
3397+
} else {
3398+
this.keepAliveTimeout = 5_000; // 5 seconds;
3399+
}
3400+
const keepAliveTimeoutBuffer = options.keepAliveTimeoutBuffer;
3401+
// Optional buffer added to the keep-alive timeout when setting socket timeouts.
3402+
// Helps reduce ECONNRESET errors from clients by extending the internal timeout.
3403+
// Default is 1000ms if not specified.
3404+
const buf = keepAliveTimeoutBuffer;
3405+
this.keepAliveTimeoutBuffer =
3406+
(typeof buf === 'number' && NumberIsFinite(buf) && buf >= 0) ? buf : 1000;
33923407
this.shouldUpgradeCallback = function() {
33933408
return this.listenerCount('upgrade') > 0;
33943409
};

0 commit comments

Comments
 (0)