Release the round-robin HTTP/2 permit when a connection starts draining#2248
Merged
Conversation
hyperxpro
force-pushed
the
fix/2214-goaway-drain-permit
branch
from
July 18, 2026 10:57
def3613 to
3cf1d06
Compare
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:
#2217 changed round-robin mode to hold the per-host connection permit for the lifetime of an HTTP/2 connection, ensuring
maxConnectionsPerHostlimits live connections. However, after a GOAWAY, the connection is immediately removed from the registry and marked as draining, while its permit is only released when the channel finally closes after all in-flight streams complete. During this drain window, the connection can no longer serve requests but still occupies both its per-host permit (and, with a combined limiter, a global connection permit). As a result, new requests cannot reuse the draining connection or acquire a new permit, eventually timing out withTooManyConnectionsPerHostException. WithmaxConnectionsPerHost=1, even same-host redirects fail, and under a combined limiter a draining connection can block new connections to unrelated hosts.DEFAULTmode does not have this issue because it releases the permit immediately after ALPN negotiation.Modification:
Release the connection permit when draining begins instead of waiting for channel close.
Http2ConnectionStatenow exposes a once-only permit release hook (setPermitRelease/releasePermitOnce) backed by anAtomicReferencelatch. In round-robin mode,NettyConnectListenerinstalls this hook and also registers acloseFuturelistener that invokes it. The GOAWAY handler inChannelManagerinvokes the same hook after marking the connection as draining and removing it from the registry. Whichever path executes first releases the permit exactly once, preventing double releases from over-incrementing the semaphore.DEFAULTmode remains unchanged. The change also avoids repeatedly readingfuture.getPartitionKey()inregisterHttp2AndManageSemaphoreand documents the connection-lifetime permit semantics inLoadBalance.Result:
A GOAWAY now immediately frees the draining connection's per-host and global connection permits, allowing a replacement connection to be established without waiting for existing streams to finish. This restores the expected behavior during server rolling restarts while preserving the connection cap. The change is covered by unit tests for drain-time permit release, double-release prevention, close-without-GOAWAY, combined-limiter behavior, concurrent once-only release, and an end-to-end HTTP/2 GOAWAY scenario that previously failed with
TooManyConnectionsPerHostException.