Repository navigation
Conversation
Motivation: A long-lived HTTP/2 client cannot reuse stream IDs. An unbounded Int increment can wrap after allocating the final positive odd identifier. Modification: Stop request admission after rendering the last valid stream. Report exhaustion to a direct client's request-side termination watcher while letting the response half drain normally. Retire managed connections after the last assignment and retain the buffered request if its source completes while the replacement connection is being established. Result: Already assigned requests drain without replay. A direct client can observe the exhaustion without losing responses; a managed client hands only unassigned work to the replacement connection. References: RFC 9113 §5.1.1: https://www.rfc-editor.org/rfc/rfc9113.html#section-5.1.1
He-Pin
force-pushed
the
fix/http2-client-stream-id-exhaustion
branch
from
November 26, 2026 17:01
ec6a834 to
64d809e
Compare
pjfanning
reviewed
Nov 26, 2026
pjfanning
left a comment
Member
There was a problem hiding this comment.
The allocator and the new rendering stage look correct to me, and the direct-connection path ends in the demux's existing request-side completion. A few points on the code:
Connecting.onUpstreamFinishis a fix of its own. On mainConnectinginheritscompleteStage(), so a request sitting in the inlet is dropped if the source completes while any connection attempt is pending, including the first one. This PR fixes that, which is good, but it is not limited to stream ID exhaustion. The same hole remains inUnconnected: after a failed attemptonFailedswitches toUnconnectedand schedules the backoff, andUnconnectedstill has the defaultonUpstreamFinish, so a buffered request is lost if the source completes during the backoff. Could that be closed here as well, with a test?- Two counters have to stay in step.
remainingRequestsinPersistentConnectionassumes exactly one stream ID per dispatched request and retires one step beforeClientRequestRenderingwould cancel. That holds today becauseretire()completesrequestOutfirst, so the later cancel is ignored. If the counts ever diverged, the cancel would reachonDownstreamFinish->onDisconnected()and every in-flight request would get a 502. Would it be more robust for theConnectedrequestOuthandler to treat aStreamIdExhaustedExceptioncause as a retire, instead of or as well as the counter? ClientStreamIdsandClientRequestRenderingneed@InternalApiand theINTERNAL APIscaladoc, like the classes around them.- In
onConnected,else if (isClosed(requestIn)) requestOut.complete()looks unreachable now: with the newConnecting.onUpstreamFinish, closed-and-not-available has already completed the stage.
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.
Motivation
HTTP/2 stream identifiers cannot be reused. A client connection that uses its last valid request stream identifier should stop accepting requests without discarding responses already assigned to it.
Modification
StreamIdExhaustedException, which callers can observe withwatchTermination. Let already assigned responses drain under the existing completion timeout.Result
The final valid request and its response are handled normally. Direct callers can distinguish request-side retirement from a response failure, and managed callers can continue on a fresh connection. Incoming GOAWAY and the opt-in graceful GOAWAY behavior are not changed by this PR.
Tests
JDK 17: six focused tests passed on each of Scala 2.13.18 and 3.3.9. MiMa, formatting, and the Java API usage sample compilation passed. Full CI was not run locally.
References