Repository navigation
Stabilize HTTP/2: fix resource leaks and RFC conformance - #2197
Merged
Merged
Conversation
hyperxpro
force-pushed
the
http2-residual-fixes
branch
from
June 14, 2026 22:02
fe46b13 to
5a6976b
Compare
4 tasks done
hyperxpro
pushed a commit
that referenced
this pull request
Nov 27, 2026
**Motivation:** When a filter asks for a replay, `NettyRequestSender.replayRequest` hands the previous channel over and then calls `sendNextRequest`, which builds the replayed request and can throw, for example when the request's body file is gone. `replayRequest` let that exception through. For a replay that an `IOExceptionFilter` asks for from a handler's catch block, after an `IOException`, the exception then left that catch block and reached `exceptionCaught`: - **Over HTTP/1.1,** the previous channel's drain callback still names the future, so `exceptionCaught` failed the request. - **Over HTTP/2,** the stream channel is discarded before the replay (since #2197), so `exceptionCaught` found no future, and the request waited until its request timeout, 60 seconds by default. **Example:** a POST with a `File` body over HTTP/2 gets a 307 after the file was deleted. The redirect refuses to resend the missing file with an `IOException`, an `IOExceptionFilter` replays the request, and building that replay throws `IllegalArgumentException` from `NettyFileBody`. **Modification:** `replayRequest` aborts the future itself when `sendNextRequest` throws, as `retry()` does for the same call. It passes the previous channel, as `replayRequest` already does when rebinding cookies or `onRetry` fails. That way an HTTP/1.1 connection's permit is back before the caller learns of the failure. The HTTP/2 stream channel holds no permit and is already closed at that point. **Result:** In that case, the request now fails at once with the exception that stopped the replay, over HTTP/2 as over HTTP/1.1. Over HTTP/1.1 the outcome is the same as before: the request fails with the same exception, and the previous connection is closed with it. **Tests:** - **`FailedReplayHttp2Test`:** the example above. - **Server:** a Netty HTTP/2 server that deletes the body file once it has received the request, then answers 307. - **Expected:** the request fails with the `IllegalArgumentException` within 10 seconds, after exactly one replay, and the client still serves a later request. - **Without the fix,** it times out. - **`FailedReplayTest`:** the same over HTTP/1.1, through TLS, because over plain HTTP a filter does not replay while the connection is open. - **Setup:** `maxConnections` is 1, and the first request's `onThrowable` sends the next request. That request needs the permit of the connection the replay came from, at the moment the caller learns of the failure. - **Without the fix,** it passes too, since `exceptionCaught` aborted with the channel. - **Aborting with `null` instead of the channel** fails it with `TooManyConnectionsException`. The request fails with the exception that stopped the replay, not with the `IOException` that led to it, as with `retry()`. ## AI disclosure Claude Code on behalf of Matthias Kurz. The commit includes `Co-Authored-By` per `AGENTS.md`. ## Test plan All on JDK 11. - [x] `./mvnw -B -ntp -Dgpg.skip=true clean verify`: 2,493 tests, 0 failures, 22 skipped; Revapi passed against 3.0.15. Docker was not running, so the skipped tests include the Testcontainers proxy tests. - [x] `FailedReplayHttp2Test` and `FailedReplayTest` 5 times: 2 of 2 each time. - [x] **Without the fix:** `FailedReplayHttp2Test` fails with a `TimeoutException` after 10 seconds; `FailedReplayTest` passes. - [x] **Aborting with `null` instead of the channel:** `FailedReplayTest` fails with `TooManyConnectionsException`; `FailedReplayHttp2Test` passes. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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:
The HTTP/2 path is newer and less hardened than HTTP/1.1. Bring its resource lifecycle, RFC 9113/9110 conformance, and connection/stream management to parity, covering flow control, multiplexing, and GOAWAY/RST/SETTINGS edge cases.
Modification:
Bind stream-slot and request-body release to the channel lifecycle, stream request bodies under flow-control backpressure, enforce RFC 9113/9110 conformance (RST_STREAM codes, 1xx interim, Expect 100-continue, TE, :authority, MAX_CONCURRENT_STREAMS=min), gate WebSocket off HTTP/2, drain pendingOpeners on GOAWAY/SETTINGS, and restore Http2ConnectionState binary compatibility. HTTP/1.1 behaviour and public API are unchanged.
Result:
Stablize HTTP/2 even futher for edge cases
Fixes #2160