Repository navigation
fix(h2): release an error-GOAWAY linger's streams while it is pending - #1875
Merged
Merged
Conversation
`Mux::release_streams_and_backends_for_error_linger` was gated by `Connection::lingers_after_error_goaway`, which only recognised a linger already draining. On TLS, a GOAWAY carrying an error code that leaves streams open goes out without `close_notify` (`ConnectionH2::output_flush_closes_connection` wants an empty stream table), so the writable pass that decides the close queues the alert in `H2Shell::linger_instead_of_closing` and leaves the linger `Linger::Pending`. When the kernel then refuses the alert's record, `kernel_refused_write` withholds the re-arm, `Mux::ready_inner`'s loop ends with the linger still pending, the release is skipped, and the `pending_links` pass can dial a backend for a stream queued by the same read pass. The next pass, once the linger drains, closed it again. The gate now treats a pending or draining linger after a non-graceful final GOAWAY as decided, so the release runs right after the frontend write that decides it, before `pending_links`. It stays idempotent and `Mux::close` finds nothing left to account for. A graceful linger and H1 are unchanged. The regression test drives a real `FrontRustls` frontend through `Mux::ready` with a full send queue; before the fix the `pending_links` pass reaches the stub proxy's routing view and panics. LIFECYCLE.md §8.1, doc/h2_mux_internals.md and the CHANGELOG describe the decided linger instead of the draining one. Refs: #1861 Refs: #1873 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 6, 2026
`an_error_goaway_linger_pending_on_close_notify_releases_before_pending_links` failed on the old `Connection::lingers_after_error_goaway` gate only through `RemoveOnlyProxy`'s generic "closing a backend only removes its session". It now runs against a dedicated `NoRoutingProxy` stub whose routing view and registration panic with "pending_links routed a stream of an error-GOAWAY linger"; what the test asserts is unchanged. `Mux::release_streams_and_backends_for_error_linger` selects the streams it recycles by `metrics.start.is_some()`. A stream in `StreamState::Link` or `Linked` always carries its start: every first entry into `Link` arms it through `SessionMetrics::service_start`, every other entry re-links a stream that was already linked, `Linked` is reached only from `Link`, and no `SessionMetrics::reset` leaves a stream in either state. A debug-only pre-condition now states that invariant before the early return, where the existing post-condition could not see it. Refs: #1875 Signed-off-by: Florentin Dubois <[email protected]>
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.
Summary
Follow-up to #1873 (#1861).
Mux::release_streams_and_backends_for_error_lingerwas gated byConnection::lingers_after_error_goaway, which checkedis_lingering(), true only once the linger isDraining.On a TLS frontend, an error GOAWAY that leaves streams open goes out without
close_notify(output_flush_closes_connectionrequires an empty stream table). The next writable pass queues the alert and setsLinger::Pending. If the kernel refuses that record,ensure_tls_flusheddoes not re-arm and the pass ends with the linger stillPending: the release was skipped, and thepending_linkspass could dial a backend for a stream queued in the same read pass, closed only on a later pass.PendingorDraining(!matches!(linger, Linger::Off) && !graceful_goaway), so the pass that decides the linger releases streams and backends beforepending_links. Graceful and H1 lingers are unchanged; the release stays idempotent andMux::closeaccounts nothing twice.LIFECYCLE.md§8.1,doc/h2_mux_internals.mdand CHANGELOG describe the decided-linger gate.h2::testsbecomespub(super)andrustls_h2_connectionpub(in crate::protocol::mux), to reuse the rustls fixture.Refs #1861, #1873
Verification
an_error_goaway_linger_pending_on_close_notify_releases_before_pending_linksdrives a realFrontRustlsfrontend throughMux::readywith aLinkstream inpending_linksand the send queue full. Red with the old gate (the pending_links routing view is reached), green with the fix.cargo test -p sozu-lib --no-default-features --features crypto-ring(1612 passed), clippy--all-targets -D warnings,cargo +nightly fmt --check,check_doc_citations.py, and the release e2etest_h2_outbound_flood_from_rst_stream: green.