Skip to content

Stabilize HTTP/2: fix resource leaks and RFC conformance - #2197

Merged
hyperxpro merged 1 commit into
mainfrom
http2-residual-fixes
Jun 14, 2026
Merged

hyperxpro merged 1 commit into
mainfrom
http2-residual-fixes

Conversation

@hyperxpro

@hyperxpro hyperxpro commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

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

@hyperxpro
hyperxpro force-pushed the http2-residual-fixes branch from fe46b13 to 5a6976b Compare June 14, 2026 22:02
@hyperxpro
hyperxpro merged commit a374830 into main Jun 14, 2026
17 checks passed
@hyperxpro
hyperxpro deleted the http2-residual-fixes branch June 14, 2026 22:14
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/2 server communication triggers random timeouts

1 participant