Repository navigation
fix(h2): linger before closing after the final GOAWAY - #1768
Merged
Merged
Conversation
Once an H2 frontend had flushed its final GOAWAY it closed at once, while the client could still be sending frames it wrote before reading the GOAWAY. A close with those frames unread, or followed by more, makes the kernel reset the connection and discard response bytes still queued in the socket. A close after a final GOAWAY(NO_ERROR) now uses the lingering close of the H1 frontend (RFC 9113 §6.8, RFC 9112 §9.6): close_notify, then shutdown(SHUT_WR), then read and drop what the client still sends until its EOF, 4 MiB, or the listener's request_timeout. A GOAWAY carrying an error does not linger, and the H2 graceful-shutdown budget still closes a lingering session during a soft stop. Fixes #1764 Signed-off-by: Florentin Dubois <[email protected]>
The lingering readable and writable passes returned before the code that adopts the mux's clock snapshot, so graceful_shutdown_deadline_elapsed compared against the instant the linger began, and a soft stop's H2 graceful-shutdown budget never closed a lingering session. Adopt the snapshot on both lingering early returns, and state the linger's actual bounds. Refs #1764 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/h2-goaway-lingering-close
branch
from
October 1, 2026 17:07
52c5f9b to
ca1ffc2
Compare
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.
Fixes #1764
Problem
Once an H2 frontend has flushed its final GOAWAY, it stops reading and closes the session at once. The client may still be sending frames it wrote before it read the GOAWAY (RFC 9113 §6.8). Closing with those frames unread, or receiving more after the close, makes the kernel send a reset. The reset discards response bytes still queued in sozu's socket, so the client can lose the end of a response it was otherwise served in full.
Fix
The close now uses the lingering close from #1742. The H1 and H2 frontends share
Linger,LINGER_MAX_BYTESanddrain_discard, which move tolib/src/protocol/mux/shared.rs. H1 behaviour is unchanged.It applies when a
writablepass that began after a final GOAWAY(NO_ERROR) decidesCloseSessionand the client has not hung up: graceful drain, soft stop, or the reply to the client's own GOAWAY. In that caseH2Shell::linger_instead_of_closing:close_notifyfirst. If it is still pending, the linger isLinger::Pending, and the next pass resumes it even though the state isErrorby then.shutdown(SHUT_WR), so the FIN follows everything sent.request_timeout, whichever comes first.Other points:
ConnectionH2::arm_timeoutandset_timeout_durationdo not move the linger deadline.Mux::timeout_innercloses a lingering frontend first.Mux::shutting_down_inner, the H2 graceful-shutdown budget is checked before the linger, and the lingeringreadable/writablepasses adopt the pass's clock, so an armed budget closes a lingering session when it elapses first. A drain started by the client's own GOAWAY does not arm that budget, so its linger runs torequest_timeout.Docs:
LIFECYCLE.md§8.1,doc/h2_mux_internals.md,doc/configure.md(request_timeout), and the CHANGELOG. Pinned code blocks indoc/h2_mux_internals.mdare re-anchored to the shiftedh2.rslines.Tests
The red baseline for the first test is
fix/h1-lingering-close(#1742, since merged), because it is the first tree that hasLinger.an_h2_frontend_lingers_after_its_final_goaway_so_the_client_reads_everything(mod.rs): a slow-reading client keeps sending after the final GOAWAY.ConnectionReset.a_linger_deferred_behind_close_notify_starts_on_the_next_pass(h2.rs, TLS): fails withgot CloseSessionwhen theLinger::Pendingassignment is removed (checked in a copy of the tree).the_final_goaway_and_close_notify_leave_in_one_tls_write: behavior change. The pass that flushes the final GOAWAY now starts the lingering close (Continuewithis_lingering()) instead of returningCloseSession. Its write-count and record-order assertions are unchanged.a_soft_stop_closes_a_lingering_h2_session_once_its_budget_elapses(mod.rs): a 1 s budget armed 3 s ago and a linger started 100 ms into it. Red on the first commit with only the test added:shutting_down()kept the session. Green once the lingering passes adopt the clock.