Skip to content

fix(h2): release an error-GOAWAY linger's streams while it is pending - #1875

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-error-linger-release-gate
Oct 6, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-error-linger-release-gate

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1873 (#1861). Mux::release_streams_and_backends_for_error_linger was gated by Connection::lingers_after_error_goaway, which checked is_lingering(), true only once the linger is Draining.

On a TLS frontend, an error GOAWAY that leaves streams open goes out without close_notify (output_flush_closes_connection requires an empty stream table). The next writable pass queues the alert and sets Linger::Pending. If the kernel refuses that record, ensure_tls_flushed does not re-arm and the pass ends with the linger still Pending: the release was skipped, and the pending_links pass could dial a backend for a stream queued in the same read pass, closed only on a later pass.

  • The gate now matches a decided error linger, Pending or Draining (!matches!(linger, Linger::Off) && !graceful_goaway), so the pass that decides the linger releases streams and backends before pending_links. Graceful and H1 lingers are unchanged; the release stays idempotent and Mux::close accounts nothing twice.
  • LIFECYCLE.md §8.1, doc/h2_mux_internals.md and CHANGELOG describe the decided-linger gate.
  • Test-only visibility: h2::tests becomes pub(super) and rustls_h2_connection pub(in crate::protocol::mux), to reuse the rustls fixture.

Refs #1861, #1873

Verification

  • New an_error_goaway_linger_pending_on_close_notify_releases_before_pending_links drives a real FrontRustls frontend through Mux::ready with a Link stream in pending_links and 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 e2e test_h2_outbound_flood_from_rst_stream: green.

`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
FlorentinDUBOIS merged commit 8714f55 into main Oct 6, 2026
37 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant