Repository navigation
Bun.serve http2: close a connection gracefully with a FIN, not with close(2) #44874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
1
commit into
main
Choose a base branch
from
robobun/bff2155a/h2-graceful-close-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+599
−47
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Operators calling await server.stop() can wait forever on an HTTP/2 connection whose GOAWAY the kernel did not take, where the base closed it at once. closeIdle at Http2Context.h:835 skips finish() when out is not empty and arms no timer: with idleTimeout 0 the socket timeout is 255 (never), and with idleTimeout > 0 every frame the peer sends re-arms it through touch() at Http2Context.h:1407 because streams.empty() holds. A WINDOW_UPDATE on stream 0 queues nothing, so MAX_QUEUED_CONTROL never ends it. Fix: a going-away connection with no streams that cannot finish yet must get the same bound as finSent, i.e. arm max(idleTimeoutS, LINGER_TIMEOUT_S) at closeIdle:835 and make touch() a no-op in that state, so onTimeout:1012 aborts it regardless of peer input. [also at: packages/bun-uws/src/Http2Context.h:1084 - Servers with
idleTimeout: 0can hold an HTTP/2 connection forever after the client's GOAWAY when the kernel did not…]Why this was flagged
A client requests a large response, grants wide flow-control windows, and stops reading the TCP socket once the whole body has been framed (the stream retires when the last byte enters
out, Http2Context.h:532-533, before the kernel took it). server.stop() reaches Http2Context::closeIdle (Http2Context.h:829-841): writeGoaway, flush (write returns 0), drainedAfterGoaway() is false because out->length() != 0, so neither finish() nor any timer is armed. With idleTimeout: 0, touch() (Http2Context.h:1076) set s->timeout to 255 (socket.c:104), so onTimeout never fires and stop() never resolves. With the default idleTimeout 10, a peer that sends any frame (PING, or WINDOW_UPDATE on stream 0 which queues no reply, Http2Context.h:1586-1591) goes through Http2Connection::onData, whose tail at :1407 calls touch() because streams.empty(), re-arming the 10 s timer each time. On the base branch closeIdle called us_socket_close on every connection with streams.empty(), so stop() resolved immediately.Verification: closeIdle (Http2Context.h:829-841) arms no finish() or timer when out->length() != 0. Base closed a streams.empty() connection at once. With idleTimeout 0, socket.c:104 sets s->timeout = 255 (never). With idleTimeout > 0, Http2Connection::onData line 1407 re-arms the timer per frame because streams are empty; stream-0 WINDOW_UPDATE (1586-1591) queues nothing, so MAX_QUEUED_CONTROL never trips.