Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const {
ArrayIsArray,
Error,
MathMin,
NumberIsFinite,
ObjectKeys,
ObjectSetPrototypeOf,
ReflectApply,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
Loading