Practical technical guides

HTTP/2 GOAWAY Says Which Requests Are Safe to Retry: Read the Last Stream ID

Use the last stream identifier and REFUSED_STREAM to separate unprocessed requests from ones that may have run.

By Sandeep Belgavi · Published 2026-12-05

Flow from Track open streams, to Read last stream ID, to Replay only the unprocessed.
Original conceptual diagram by Sandeep Belgavi.

A deploy that fails some requests and not others

A rolling deploy of the order service at Belgavi's Book Store produces a handful of errors in the client that calls it over HTTP/2. Most failed requests are reads, and the client retried them without trouble. A few are refund submissions, and the client either gave up or, worse, retried one that the old server instance had already processed. The difference between a safe retry and a duplicate refund was in a frame the client received and ignored: GOAWAY, and the stream identifier inside it.

HTTP/2 multiplexes many requests over one connection, each on its own stream. When a server wants to stop using a connection, during a deploy, a connection rotation or an overload, it cannot simply close the socket without leaving the client unsure which requests were handled. GOAWAY exists to answer that question precisely, and RFC 9113 is unusually explicit about what a client may do with the answer.

What the last stream identifier means

RFC 9113 section 6.8 defines the last stream identifier in a GOAWAY frame as the highest-numbered stream for which the sender might have taken some action or might yet take action. All streams up to and including that identifier might have been processed in some way, where processed means some data was passed to a higher layer that might have acted on it. Streams with higher identifiers were not processed, and the RFC says activity on them can be safely retried using a new connection.

Section 8.7 turns that into a reliability guarantee. HTTP/2 offers two ways for a server to promise a request was not processed: a GOAWAY whose last stream identifier is lower than the request's stream, and a RST_STREAM with the REFUSED_STREAM error code. Requests that have not been processed have not failed, and clients may retry them automatically, even those with non-idempotent methods. The server must not make that promise unless it can guarantee it.

For the lower-numbered streams the rule goes the other way. If a stream at or below the identifier was not closed completely before the connection closed, reattempting it is not possible except for idempotent actions such as GET, PUT or DELETE. Those requests may have been executed.

A worked example with an HTTP/2 library

The behaviour can be reproduced in memory with the Python h2 library, version 4.3.0, without a network. A client opens a connection and sends four POST requests to a refund endpoint. Client-initiated streams use odd identifiers, so they are 1, 3, 5 and 7. The server reads all four header blocks, decides to stop after stream 3 and sends GOAWAY with NO_ERROR and a last stream identifier of 3.

StreamRequestClassification from GOAWAY 3Client action
1POST refund for CASE-2201may have been processedwait for its response on the old connection; if none, retry only with an idempotency key
3POST refund for CASE-2202may have been processedsame as stream 1
5POST refund for CASE-2203not processedretry on a new connection
7POST refund for CASE-2204not processedretry on a new connection

The library reports the frame as a ConnectionTerminated event carrying the last stream identifier and error code. After receiving it, the client connection refused to open another stream and raised a protocol error, which is the right behaviour: new requests belong on a new connection.

def classify(goaway_last_stream_id, open_streams):
    safe, uncertain = [], []
    for stream_id, request in open_streams.items():
        if stream_id > goaway_last_stream_id:
            safe.append(request)          # guaranteed unprocessed: replay on a new connection
        elif not request.complete:
            uncertain.append(request)     # may have run: replay only if idempotent or deduplicated
    return safe, uncertain

Note that the server in this example had already read the headers of streams 5 and 7. Reading is not processing. What matters is whether the request was handed to application code, and the server, not the client, is the authority on that.

Graceful shutdown takes two frames

A server that sends one GOAWAY with the current highest stream identifier can still lose requests: a client may have sent new streams that are in flight and that the server has not yet seen. RFC 9113 recommends that a server attempting a graceful shutdown first send GOAWAY with the last stream identifier set to 2^31-1 and NO_ERROR. That tells the client that shutdown is imminent and new requests are prohibited, without committing to which in-flight streams will be handled. After at least one round trip, the server sends a second GOAWAY with the real last stream identifier, then keeps the connection open until the streams at or below it complete.

The RFC also forbids a sender from increasing the identifier in a later GOAWAY, because the peer may already have retried the unprocessed requests elsewhere. A client can rely on the lowest value it has seen.

What a client should implement

  1. Track every open stream with its request and whether its response has completed.
  2. On GOAWAY, stop sending on that connection and open a new one for new requests.
  3. Replay requests on streams above the last stream identifier immediately, on the new connection, whatever their method.
  4. Let streams at or below the identifier finish on the old connection; the server said it might still act on them.
  5. If the old connection closes before such a stream completes, retry only idempotent requests, or non-idempotent requests that carry an idempotency key the server deduplicates.
  6. Treat RST_STREAM with REFUSED_STREAM the same way as a stream above the identifier.

Many HTTP/2 client libraries do part of this. Check what yours does on GOAWAY before writing retry logic on top of it; a library that replays unprocessed streams and an application retry loop that replays them again can double the traffic during every deploy.

Server side

A server or proxy draining for a deploy should send the initial GOAWAY early, keep accepting frames for streams it already admitted, finish them, and only then send the final GOAWAY and close. It must not report a stream as unprocessed after any of its data reached application code; that would invite the client to replay a request that ran. A load balancer between client and server adds a second HTTP/2 connection with its own GOAWAY semantics, so test retries end to end, not only against the backend.

Failure modes

Ignoring the identifier. A client that treats every stream on a closed connection as failed either drops safe-to-retry work or replays unsafe work.

Retrying non-idempotent requests below the identifier. This is how duplicate refunds happen. Pair POST endpoints with idempotency keys so that the uncertain case becomes safe.

Single-phase shutdown. Sending only the final GOAWAY loses streams the client sent during the last round trip.

Closing immediately after GOAWAY. The RFC allows the sender to keep the connection open until in-progress streams finish. A server that closes right away turns all of them into uncertain outcomes.

Retry loops stacked on library retries. Two layers replaying the same unprocessed request double the load exactly when a server is draining.

When this is not your problem

If every request on the connection is idempotent, any retry is safe and the identifier only saves duplicate work. If the client uses HTTP/1.1 with one request per connection, there is no multiplexing and no GOAWAY. And if a managed client library already implements GOAWAY replay correctly and the application never retries on its own, the job is to verify that behaviour, not to rebuild it.

Verification

  • An in-memory test with an HTTP/2 library that sends GOAWAY with a chosen identifier and asserts which requests the client replays.
  • A deploy test that drains a server under load and counts requests that were replayed, duplicated or lost.
  • A server test asserting that streams handed to application code are never reported above the GOAWAY identifier.
  • A check that POST endpoints exposed over HTTP/2 accept idempotency keys.

The companion example contains the in-memory h2 scenario above with assertions for each stream's classification.

Primary references and authorship

Sources read December 5, 2026. Original explanations, measurements and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/http2_goaway_retry. Views are my own and do not represent any employer, past or present.