http: add Server.drainTimeout for gracefully closing idle connections #60621
+64
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an initial draft implementation for #60617 .
Please see that issue for a detailed discussion of the proposed enhancement.
The implemented behaviour is:
drainStartedtotruerequestListenerin theServerconstructor, for any then received requests, we set theConnection: closeresponse header, leading to the client to close the connection itself (avoiding the race condition mentioned in Support draining of keep-alive connections on http.Server.close() #60617 )drainTimeoutbefore doing anything with idle connectionsThe default behaviour of immediately closing idle connections on "graceful" server shutdown is preserved with the default of
dranTimeout== 0.I am aware of the fact that currently, missing are (as per committer guidelines):
But I'd like to first gauge the possibility of this feature actually making it through, eventually.
Currently, all existing tests (via
make test) pass successfully and using the patched node executable, the following results in the expected behaviour of the server still accepting requests on idle connections for 5s and responding to them withConnection: closebefore finally shutting down:What's next
Connection: close) until the number of open connections reaches zero; instead of waiting the fulldrainTimeout(EDIT: actually, I added that now)