Repository navigation
fix(server): answer requests that arrive before the request listener is attached - #56642
Open
doublepi123 wants to merge 1 commit into
Open
doublepi123 wants to merge 1 commit into
doublepi123 wants to merge 1 commit into
Conversation
…is attached NodeHttpServer listens before HttpRouter.serve adds the "request" listener, and building the route layers in between takes a few hundred ms. Node drops a request emitted with no listener, so a client that connects as soon as the port opens waits forever. Hold those requests and replay them once the real listener is attached. Closes anomalyco#56641
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
This branch has not been deployed
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.
Issue for this PR
Closes #56641
Type of change
What does this PR do?
NodeHttpServer.layerstarts listening beforeHttpRouter.serveadds the"request"listener. The route layers are built in between, which takes a few hundred ms. A request that arrives in that window is emitted to no listener, so Node drops it and the client waits on an open socket forever.serverLayernow registers a temporary"request"listener that holds early requests. When the real listener is added (detected withnewListener), the temporary one is removed and the held requests are re-emitted on the next tick.newListenerfires before the listener is actually added, which is why the replay waits a tick. After startup there is no extra listener and no per-request overhead.Targets
v1because that is where 1.x is released from.devalready avoids this by answering 503 until the routes are ready.How did you verify your code works?
httpapi-listen.test.tsthat startsServer.listenand sends a request on the first accepted connection. It times out without the fix and passes with it.bun test test/server/httpapi-listen.test.ts: 12 pass, run 3 times.bun run typecheckpasses. Intest/server/,project-copy.test.tsfails the same way with and without this change; everything else passes.opencode servefrom source and sent/api/infothe moment the port accepted. Without the fix 4/4 hung. With the fix 6/6 got 200 after about 0.6 s.Screenshots / recordings
N/A
Checklist