Skip to content

mux-h2: a soft-stop during an incomplete header block drops the request without a final GOAWAY #1647

Closed

Description

@FlorentinDUBOIS

Summary

A soft-stop that lands while an H2 connection's only stream is still receiving its HEADERS/CONTINUATION field block closes the session in the same drain pass. The request is lost, and the client never receives a final GOAWAY carrying the real last_stream_id, so it cannot tell whether that stream was processed.

Mechanism

  • ConnectionH2::handle_header_state (lib/src/protocol/mux/h2.rs) creates the stream via ConnectionH2::create_stream when the HEADERS frame header arrives, and ConnectionH2::handle_headers_frame parks the connection in H2State::ContinuationHeader while END_HEADERS is unset. The stream stays StreamState::Idle (Stream::new, lib/src/protocol/mux/stream.rs) until the block completes and is routed.
  • Mux::shutting_down_inner (lib/src/protocol/mux/mod.rs) sets can_stop = false only for StreamState::Linked(_) and non-quiesced StreamState::Unlinked streams. An Idle stream mid-reassembly does not hold the session open.
  • Once graceful_goaway has queued and flushed the advisory GOAWAY(NO_ERROR, 2^31-1), Connection::has_pending_write is false, shutting_down_inner returns true, and Server::shut_down_sessions (lib/src/server.rs) closes the session.
  • The final GOAWAY (the AlreadyDraining arm of ConnectionH2::graceful_goaway, i.e. ConnectionH2::goaway(H2Error::NoError) with H2StreamTable::highest_peer_stream_id) is never sent on this path.

Scenario

  1. Client opens an H2 connection and sends HEADERS for stream 1 without END_HEADERS (a large request header block split across frames, or a slow client).
  2. The worker receives a soft stop before the CONTINUATION arrives.
  3. The client receives the advisory GOAWAY (last_stream_id = 2^31-1) and then the connection closes. Its request is not served, and nothing tells it the request was not processed.

test_h2_graceful_drain_mid_header_block_sends_goaway_before_closing (e2e/src/tests/h2_tests.rs) reproduces the shape. It asserts only that a GOAWAY precedes the close, which #1637 fixed.

Why it matters

RFC 9113 §6.8: "Endpoints SHOULD always send a GOAWAY frame before closing a connection so that the remote peer can know whether a stream has been partially processed or not." The advisory GOAWAY at 2^31-1 claims nothing about which streams were processed. §6.8 also describes the graceful sequence: initial GOAWAY at 2^31-1, then, "after allowing time for any in-flight stream creation (at least one round-trip time)", a GOAWAY with the updated last stream identifier. Here the in-flight stream is neither given that time nor reported.

Possible directions (not decided)

  • Treat a stream whose header block is still being reassembled (H2State::ContinuationHeader / ContinuationFrame on the frontend) as keeping the session alive in Mux::shutting_down_inner, bounded by the existing h2_graceful_shutdown_deadline_seconds forced-close budget.
  • Or, when closing a draining session, send the final GOAWAY with the real last_stream_id first (excluding the incomplete stream), so the client knows it may retry.

Found while working on #1637; out of that change's scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions