Skip to content

feat: support two-phase HTTP/2 server shutdown - #1664

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:feat/http2-two-phase-server-goaway
Open

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:feat/http2-two-phase-server-goaway

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

A single GOAWAY fixes the last stream ID immediately. During a rolling restart or connection-age retirement, clients can then have to retry requests they sent before seeing the GOAWAY.

Modification

Add the opt-in server graceful-shutdown-advisory-timeout as an independent setting with Scala and Java APIs; it no longer uses internalSettings. A single advisory timer gives already-sent requests a chance to arrive. The first final GOAWAY fixes the highest admitted stream and stops accepting new streams. When the hard deadline is too short for the advisory, send the final boundary early and leave the rest of the deadline to drain. The default remains single-phase; client behavior is unchanged. The JVM constructor and copy bridges preserve their published 2.0.0 signatures; generated internal case-class shape is not promised.

Result

Requests already in flight get a chance to reach the server before it fixes the final boundary. Accepted streams can drain, including their final DATA, within the existing deadline. This PR changes only the server's sending behavior; client capability is separate and #1445 is not a dependency.

Tests

On JDK 17, 13 focused settings, boundary-model and ordinary shutdown tests passed on each of Scala 2.13.18 and 3.3.9, including independent reruns. Java duration and 2.0.0 constructor/copy linkage checks, scoped settings MiMa, formatting and whitespace checks passed. The error-boundary logic was checked in source and the state model; no malformed peer input, full CI or h2spec was run locally.

References

Merge order

The verified integration order for the HTTP/2 server settings is #981 first, then this advisory change. The follow-up on Apache main should retain both independent settings and share the published constructor/copy bridges without modifying internalSettings. Both lower layers were compiled and tested together locally; do not reuse that result if either layer changes.

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state machine reads well and the default (0s) path is unchanged as far as I can trace. Two points on the code:

The setting lives in the internalSettings slot. GracefulShutdownSettings extends Http2InternalServerSettings is stored in internalSettings by fromSubConfig and read back by pattern match. This is the same concern I raised on #981, #1556 and #1589: the slot holds one value, so withInternalSettings(x) silently turns the advisory off, and any other PR that parks its setting there will overwrite this one or be overwritten by it. It also means the setting is config-only, with no withGracefulShutdownAdvisoryTimeout in either DSL, unlike max-connection-age* beside it. I would rather this were a real field on Http2ServerSettingsImpl with accessors in both DSLs, and we agree one approach for all of these PRs.

A hard deadline shorter than the advisory wait closes without the final GOAWAY. The AdvisoryTimeout timer is not capped by deadline, and it is armed twice (once when queued, again when the PING is handed to the transport), so the wait can be up to twice the setting. With, say, an advisory timeout of 2s and terminate(500.millis) or a small max-connection-age-grace, CompletionTimeout fires first and the stage completes. The peer has then only seen GOAWAY(2^31-1), and streams admitted during the window are cut off, where single-phase shutdown would have refused them with a retryable REFUSED_STREAM. The "honor a later shorter hard deadline" test pins this, so I take it to be intended, but it makes the tight-deadline case worse than with the feature off. Could the advisory wait be capped by the remaining deadline, or the final GOAWAY be sent before the forced close?

Smaller, and not blocking: with the feature enabled, sendGoAway records the boundary for error GOAWAYs too, which do not close the connection (the existing FIXME). If one advertised 5 and stream 7 was admitted afterwards, a later terminate goes single-phase with min(7, 5) = 5, so further frames on stream 7 are refused while its handler keeps waiting for the body until the hard deadline. With the feature off the boundary is 7 and the stream finishes.

Test gaps worth filling: the boundary excluding a stream refused for maxConcurrentStreams (the reason lastAdmittedStreamId exists), and an error GOAWAY arriving while the advisory is pending.

Motivation:
Give already-sent requests a chance to reach a shutting-down server without delaying the hard termination deadline.

Modification:
Make the advisory GOAWAY and PING opt-in. Use one timeout across PING handoff and acknowledgment. If the hard deadline cannot accommodate the advisory, announce the final boundary immediately. Share the boundary when any final GOAWAY is announced: it excludes requests refused before admission and does not move once admission closes. Keep the timeout separate from internal settings, with Scala and Java accessors and bridges for the released server constructor and copy methods.

Result:
The settings compose independently and the server drains admitted requests without reopening admission or extending the hard deadline. The default remains single-phase and HTTP/1.x is unaffected.

References:
RFC 9113 §6.8; Netty Http2FrameCodecTest.sendGoAway; Apache Pekko HTTP apache#1664 peer review. No Netty source copied.
@He-Pin
He-Pin force-pushed the feat/http2-two-phase-server-goaway branch from 0defb96 to 9dbae92 Compare November 27, 2026 02:17
@He-Pin
He-Pin requested a review from pjfanning November 27, 2026 02:18

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushGOAWAY in Http2Demux is also rewritten by #1665. Here every GOAWAY goes through sendFinalGoAway/freezeAdmissionBoundary, which falls back to lastStreamId() when there is no boundary (always the case on the client). #1665 needs the client to advertise 0 after its graceful GOAWAY (goAwayLastStreamId()). Whichever lands second has to fold the two together, otherwise a later error GOAWAY on the client (e.g. ping-ack timeout) raises the boundary again.

Minor: Http2ServerSettings.fromSubConfig guards the new key with hasPathOrNull ... else Duration.Zero although reference.conf always defines it. No other setting in this file does that, and it hides a missing or misspelt key instead of failing fast.

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.

2 participants