fix(ext/node): drain keep-alive connections on http server.close()#35614
Open
bartlomieju wants to merge 1 commit into
Open
fix(ext/node): drain keep-alive connections on http server.close()#35614bartlomieju wants to merge 1 commit into
bartlomieju wants to merge 1 commit into
Conversation
`server.close()` tore down existing keep-alive connections as soon as the in-flight response finished, so a follow-up request on the same socket was never served and the close callback fired immediately. Node keeps existing keep-alive connections open so in-flight and subsequent requests on them finish, and only fires the close callback once those connections end. `resOnFinish` had a Deno-only branch that destroyed the socket when the server was no longer listening. Remove it so the keep-alive timeout is set like Node, letting the connection drain. Closes #35609
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Deno's
node:httpserver.close()diverged from Node. Per Node semantics,server.close()stops accepting new connections but keeps existing keep-aliveconnections open so in-flight and subsequent requests on them finish; the close
callback only fires once those connections end. Under Deno,
server.close()tore down the existing keep-alive connection as soon as the in-flight response
finished, so a follow-up request on the same socket was never served and the
close callback fired immediately.
The cause was a Deno-only branch in
resOnFinishthat destroyed the socketwhen the server was no longer listening, instead of setting the keep-alive
timeout. This branch was introduced in the llhttp rewrite (#33208) with a note
about preventing timer leaks, but it breaks the graceful-drain behavior that
frameworks like fastify rely on for graceful shutdown (serving HTTP 503 to
in-flight connections while closing). Removing it makes the connection drain
like Node: the keep-alive timeout (or a
Connection: closerequest) eventuallyends the socket.
Adds a regression test in
tests/unit_node/http_test.tsthat callsserver.close()during the first request and asserts a second request on thesame keep-alive socket is still served.
Closes #35609