Skip to content

fix: drain HTTP/2 servers after client GOAWAY - #1669

Draft
He-Pin wants to merge 3 commits into
apache:mainfrom
He-Pin:fix/http2-server-received-goaway
Draft

He-Pin wants to merge 3 commits into
apache:mainfrom
He-Pin:fix/http2-server-received-goaway

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 26, 2026

Copy link
Copy Markdown
Member

Motivation

When an HTTP/2 client sends GOAWAY(NO_ERROR), the server should stop accepting new streams without cutting off requests it has already accepted.

Modification

  • Reuse the server's graceful termination path when it receives GOAWAY(NO_ERROR). Send the reciprocal GOAWAY with the server's last accepted client stream ID, not the ID from the client's frame.
  • Keep accepted uploads, bodies, and trailers flowing within the existing pekko.http.server.http2.max-connection-age-grace timeout. The default remains 30 seconds; infinite opts out of the deadline. Repeated GOAWAY frames do not extend it.
  • Leave handling of non-NO_ERROR GOAWAY unchanged.

Result

The server stops admitting new streams and lets accepted exchanges finish within its existing shutdown policy.

Tests

  • Both receive-direction regressions failed on the parent because no reciprocal frame was sent; the idle local-shutdown control passed.
  • On JDK 17, 15 focused tests passed on each of Scala 2.13.18 and 3.3.9. Scalafmt and Scala 2 http-core MiMa passed. Paradox rendering was not verified in this run.

References

Dependency

Stacked on #1445, whose stack also includes #1440. This draft targets Apache main, so the full PR diff includes the parent stack. Use the follow-up-only diff for review. Keep this draft until #1445 merges and the follow-up is rebased on main.

Motivation:
A clean transport read close is not an HTTP/2 stream end. A client
should keep already completed response bodies and trailers without
retaining abandoned entities indefinitely or dropping accepted
responses while reporting unanswered requests.

Modification:
Retire only the client writer and request admission on clean read EOF.
Drain completed response entities within the existing completion
timeout, respecting earlier deadlines. Complete or fail the response
stream without overtaking its already accepted responses; keep the
managed client's disconnect handling and avoid replaying requests.
Retain the current server path and normal stream ordering.

Result:
An accepted response survives transport retirement, and queued
responses are delivered before a direct connection reports unanswered
requests. The configured deadline releases abandoned buffers and
settles a client that asks for no more responses.

Tests:
JDK 17, Scala 2.13.18 and 3.3.9. Six focused typed client checks and
two existing ordinary HTTP/2 flow controls per version; scoped
formatting, header checks, and http-core MiMa.

References:
Addresses review on apache#1440. Related apache#1445 and apache#1525.
RFC 9113 Section 8.1.
Motivation:
A graceful GOAWAY closes request admission on the receiving connection,
but does not cancel exchanges the peer has accepted.

Modification:
Stop opening client streams as soon as the peer retires the connection.
Remove requests still queued at the transport boundary or above the
advertised limit; allow accepted uploads and responses to finish.
Keep managed retries limited to requests not dispatched on the old
connection and retain completed response entities for their consumers.
Bound draining from the first graceful GOAWAY with the existing client
completion timeout without extending an earlier deadline. Close the
quiescent writer without canceling transport input ahead of draining
already accepted response bodies. Treat subsequent read termination as
idempotent.

Result:
A replacement connection can accept a fresh request without replaying a
dispatched sibling or losing an accepted upload, response, or trailer.

Tests:
Exercise the ordinary client and managed connection with typed HTTP/2
events, including queued admission, accepted uploads, cancellation,
a decreasing stream boundary, completed response trailers, reconnect,
and retirement of an unfinished local streaming upload on a controlled
deadline without disturbing its replacement connection.
Retain the clean read-completion cases and ordinary TLS streamed
response coverage from the prerequisite.

References:
RFC 9113 section 6.8; apache#1440; apache#1445
Motivation: The server does not begin retirement when a client sends a graceful HTTP/2 GOAWAY.

Modification: Start the existing graceful server drain using its own accepted stream boundary and server grace period. Keep accepted streams and their response trailers intact.

Result: Idle connections close; active requests can finish without a repeated peer notice extending the deadline.

Tests: Focused JDK 17 Scala 2.13 and 3.3 suites; 15 passed on each axis.

References: RFC 9113 section 6.8; stacked on apache#1445.
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.

1 participant