diff --git a/lib/_http_server.js b/lib/_http_server.js index c5681725ca5401..1db0692c2fbef0 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -25,7 +25,6 @@ const { ArrayIsArray, Error, MathMin, - NumberIsFinite, ObjectKeys, ObjectSetPrototypeOf, ReflectApply, @@ -556,12 +555,6 @@ function Server(options, requestListener) { storeHTTPOptions.call(this, options); - // Optional buffer added to the keep-alive timeout when setting socket timeouts. - // Helps reduce ECONNRESET errors from clients by extending the internal timeout. - // Default is 1000ms if not specified. - const buf = options.keepAliveTimeoutBuffer; - this.keepAliveTimeoutBuffer = - (typeof buf === 'number' && NumberIsFinite(buf) && buf >= 0) ? buf : 1000; net.Server.call( this, { allowHalfOpen: true, noDelay: options.noDelay ?? true, @@ -1031,6 +1024,9 @@ function resOnFinish(req, res, socket, state, server) { // Extend the internal timeout by the configured buffer to reduce // the likelihood of ECONNRESET errors. // This allows fine-tuning beyond the advertised keepAliveTimeout. + validateInteger(server.keepAliveTimeoutBuffer, 'keepAliveTimeoutBuffer', 0); + validateInteger(server.keepAliveTimeout, 'keepAliveTimeout', 0); + socket.setTimeout(server.keepAliveTimeout + server.keepAliveTimeoutBuffer); state.keepAliveTimeoutSet = true; }