Skip to content

Commit 0efefc1

Browse files
committed
http2: fix keepAliveTimeout with allowHTTP1
1 parent 3ab9dd8 commit 0efefc1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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
};

test/parallel/test-http2-https-fallback-http-server-options.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const ca = fixtures.readKey('fake-startcom-root-cert.pem');
2020
function onRequest(request, response) {
2121
const { socket: { alpnProtocol } } = request.httpVersion === '2.0' ?
2222
request.stream.session : request;
23+
// Verify that keepAliveTimeout is set when allowHTTP1 is true
24+
assert.strictEqual(typeof request.socket.server.keepAliveTimeout, 'number');
25+
assert.strictEqual(request.socket.server.keepAliveTimeout, 5000);
2326
response.status(200);
2427
response.end(JSON.stringify({
2528
alpnProtocol,

0 commit comments

Comments
 (0)