Skip to content

Fix an HTTP/2 stream I/O error ending the other streams on its connection - #7564

Merged
joviegas merged 4 commits into
masterfrom
joviegas/h2-timeout-retry-connection
Nov 19, 2026
Merged

joviegas merged 4 commits into
masterfrom
joviegas/h2-timeout-retry-connection

Conversation

@joviegas

@joviegas joviegas commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation and Context

  1. An I/O error on one HTTP/2 stream ends every stream on the connection. Since 2.10.64 (Shutting down h2 connection if there's an I/O error on the streams. #1645), a stream I/O error should retire the connection, but Http2SettingsFrameHandler closes it first. Other streams fail or return a partial body with no error. A GOAWAY that refuses an in-flight stream does the same.
  2. A retired connection may never close. Http2MultiplexedChannelPool should close a retired connection once its last stream ends, but the check in release misses that last release. A failed stream acquire skips the check entirely, so a connection that gets a GOAWAY with no open streams stays open. Fixing 1 alone would leave every retired connection open, so both fixes ship together.
  3. client.close() truncates in-flight streams. Streams close without an error, so a body with no Content-Length comes back partial.

Modifications

  1. A stream retires its connection directly. On an IOException or TimeoutException, Http2StreamExceptionHandler now calls MultiplexedChannelRecord.closeToNewStreams() instead of sending an exception through the pipeline, so no handler can close the connection. A GOAWAY now ends only the streams above the last stream ID and leaves the rest running.
  2. A retired connection closes once it drains. MultiplexedChannelRecord closes a retired connection when it has no open streams and no pending acquires. The check runs on the event loop after every release, failed acquire, retire, GOAWAY, and idle check. closeIfIdle now checks for retirement first. It used to zero the available stream count, so a retired connection never looked drained. An acquire on a retired connection now fails with the reason: a GOAWAY or an I/O error on another stream.
  3. client.close() fails in-flight streams. Each in-flight stream fails with an IOException caused by ClosedChannelException, the same error a server-side close produces.

Behavior changes:

  • When one HTTP/2 request hits a read timeout, the SDK stops sending new requests on that connection and closes it after the requests already on it finish. Before, the timeout closed the connection at once, so those requests failed or returned a partial body. Now they succeed.

  • If the connection itself is dead, its other requests now fail at the next unanswered health-check PING (sent every 5 s by default) or at their own read timeout, not at the first timeout. The SDK retries them on a new connection. The cost is that delay, on a connection that is already broken.

  • Closing the client while HTTP/2 requests are in flight now fails those requests with an IOException. Before, they completed with a partial body and no error. Code that waits for its requests to finish before closing the client sees no change.

Testing

Added and updated JUnit tests

AI tools

  • I wrote this pull request description myself, not with an AI tool
  • I have reviewed all changes in this pull request myself, including any generated by AI tools

License

  • I confirm that this pull request can be released under the Apache 2 license

@joviegas
joviegas requested a review from a team as a code owner November 17, 2026 16:59
@joviegas
joviegas force-pushed the joviegas/h2-timeout-retry-connection branch from fccce32 to 753dba6 Compare November 17, 2026 21:27
@joviegas
joviegas force-pushed the joviegas/h2-timeout-retry-connection branch from 753dba6 to 32a9656 Compare November 18, 2026 00:47
@joviegas
joviegas requested a review from alextwoods November 18, 2026 00:56
@joviegas
joviegas force-pushed the joviegas/h2-timeout-retry-connection branch from 1411cae to 886fcc8 Compare November 18, 2026 17:44
@joviegas
joviegas force-pushed the joviegas/h2-timeout-retry-connection branch 4 times, most recently from 14a9384 to b9eeaa1 Compare November 18, 2026 21:40
@joviegas
joviegas force-pushed the joviegas/h2-timeout-retry-connection branch from b9eeaa1 to f3365a1 Compare November 18, 2026 21:47
@joviegas
joviegas enabled auto-merge November 19, 2026 15:58
@joviegas
joviegas added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit 88518ff Nov 19, 2026
13 of 14 checks passed
@github-actions

Copy link
Copy Markdown

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants