What is the problem this feature will solve?
Our services use a staged graceful-shutdown strategy that separates stopping new TCP connections from draining existing HTTP keep-alive connections.
During the draining phase, we want existing connections to remain available for subsequent requests, subject to normal connection timeouts and an application-controlled shutdown deadline.
Since Node.js 19, http.Server.close() automatically closes idle keep-alive connections. As confirmed in #53939, this is intentional. However, it prevents us from using server.close() solely to stop accepting new TCP connections while retaining existing connections for that draining phase.
The concern is not that closing idle connections aborts requests already being processed. It is that clients may still attempt to reuse established connections as shutdown begins. We need application-level control over when those connections are retired.
Retaining idle connections would not eliminate all connection-reuse races, but it would let applications explicitly manage this phase of shutdown without relying on monkey-patching.
What is the feature you are proposing to solve the problem?
Provide a documented, supported opt-out from the automatic closure of idle keep-alive connections in http.Server.close().
For example, an illustrative API could be:
server.close({ closeIdleConnections: false }, callback);
A server configuration option or another supported API providing the same behavior would also work.
With the opt-out enabled, the server would:
- Stop accepting new TCP connections.
- Retain existing idle keep-alive connections, subject to normal connection timeouts.
- Allow further requests on existing connections during an application-managed draining phase.
- Preserve the existing completion semantics: the close callback waits for the server's connections to end.
The default behavior should remain unchanged. Applications using the opt-out would be responsible for enforcing a shutdown deadline and explicitly closing any remaining connections.
This is a request for application-controlled connection draining, rather than a request to revert the default behavior discussed in #53939.
What alternatives have you considered?
Our current workaround is to replace the public method before shutdown:
server.closeIdleConnections = () => undefined;
server.close(callback);
This relies on server.close() internally calling the overridable closeIdleConnections() method. It is not a documented configuration mechanism and could stop working if that internal implementation changes.
It also makes server.closeIdleConnections() itself unavailable for explicitly closing idle connections later unless we preserve and invoke the original method.
A supported opt-out would let us control shutdown behavior without replacing a Node.js API method.
What is the problem this feature will solve?
Our services use a staged graceful-shutdown strategy that separates stopping new TCP connections from draining existing HTTP keep-alive connections.
During the draining phase, we want existing connections to remain available for subsequent requests, subject to normal connection timeouts and an application-controlled shutdown deadline.
Since Node.js 19,
http.Server.close()automatically closes idle keep-alive connections. As confirmed in #53939, this is intentional. However, it prevents us from usingserver.close()solely to stop accepting new TCP connections while retaining existing connections for that draining phase.The concern is not that closing idle connections aborts requests already being processed. It is that clients may still attempt to reuse established connections as shutdown begins. We need application-level control over when those connections are retired.
Retaining idle connections would not eliminate all connection-reuse races, but it would let applications explicitly manage this phase of shutdown without relying on monkey-patching.
What is the feature you are proposing to solve the problem?
Provide a documented, supported opt-out from the automatic closure of idle keep-alive connections in
http.Server.close().For example, an illustrative API could be:
A server configuration option or another supported API providing the same behavior would also work.
With the opt-out enabled, the server would:
The default behavior should remain unchanged. Applications using the opt-out would be responsible for enforcing a shutdown deadline and explicitly closing any remaining connections.
This is a request for application-controlled connection draining, rather than a request to revert the default behavior discussed in #53939.
What alternatives have you considered?
Our current workaround is to replace the public method before shutdown:
This relies on
server.close()internally calling the overridablecloseIdleConnections()method. It is not a documented configuration mechanism and could stop working if that internal implementation changes.It also makes
server.closeIdleConnections()itself unavailable for explicitly closing idle connections later unless we preserve and invoke the original method.A supported opt-out would let us control shutdown behavior without replacing a Node.js API method.