Skip to content

feat: send GOAWAY on opt-in HTTP/2 client graceful close - #1665

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:feat/http2-client-graceful-goaway
Open

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:feat/http2-client-graceful-goaway

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

A direct HTTP/2 client currently closes the connection after its request source finishes and outstanding responses drain. Some peers can shut down more cleanly when the client first signals that it is closing the HTTP/2 connection.

Modification

  • Add pekko.http.client.http2.send-goaway-on-graceful-close, off by default, with Scala and Java settings access.
  • When enabled, send one GOAWAY(NO_ERROR) on normal request-source completion for direct connections. The last-stream ID is 0 because this client does not accept server push. Preserve the existing response drain and completion timeout.
  • Do not send this signal on request-source failure or cancellation. Managed and pooled connections keep their existing behavior.

Result

Direct HTTP/2 clients can opt in to a graceful protocol close without changing the default or dropping outstanding responses. The existing concrete client settings retain their 21-field binary shape.

Tests

  • On JDK 17, 18 settings tests and 7 focused HTTP/2 tests passed on each of Scala 2.13.18 and Scala 3.3.9.
  • Consumers compiled against the Pekko HTTP 2.0.0 artifacts pass against the patch, covering the concrete constructor, defaulted copy, apply, and extractor. The compiled public settings consumer works unchanged.
  • Scoped settings MiMa and formatting checks passed. The Java documentation snippets compiled in the original validation. Full CI has not been verified on this commit.

References

Motivation: Let a direct HTTP/2 client notify the peer when it stops opening requests while allowing existing responses to finish.

Modification: Add a default-off option for normal request-source completion. Reuse the existing drain timeout and keep the released client settings constructor, copy and product layout by storing the opt-in in the existing internal settings slot.

Result: An opted-in direct connection signals graceful close and continues draining. Default, managed and pooled behavior is unchanged. Settings copies keep the option without changing old JVM signatures.

References: RFC 9113 section 6.8.
@He-Pin
He-Pin force-pushed the feat/http2-client-graceful-goaway branch from 927b283 to beec719 Compare November 26, 2026 16:45
@He-Pin
He-Pin requested a review from pjfanning November 26, 2026 16:47

@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 engine change looks right to me: the GOAWAY goes through the control-frame queue after any request HEADERS, in-flight streams still drain, and nothing changes with the option off. Two points on the code:

The setting is stored by wrapping internalSettings. GracefulGoAwayEnabled(delegate) wraps the slot, sendGoAwayOnGracefulClose is true when the slot holds the wrapper, and withInternalSettings re-wraps to keep the flag. This is the same concern as on #981, #1556, #1589 and now #1664, each of which uses the slot in a different way:

  • settings.internalSettings no longer returns what was passed to withInternalSettings once the flag is on, so any reader has to know to unwrap it.
  • copy(internalSettings = Some(x)) on the impl silently drops the flag.
  • It does not compose with the other PRs: each would overwrite, or fail to recognise, the others' value in the slot.

I would rather this were a real field on Http2ClientSettingsImpl, and that we settle one approach for all of these PRs.

withoutClientGoAway has no test. It is the only thing that stops managedPersistentHttp2* from sending the GOAWAY when the wrapper completes its inner request source on retirement or downstream cancellation, and removing the two withoutClientGoAway. prefixes would leave every test green. Could you add a case with the option on and a managed connection, asserting that no GOAWAY is sent on cancel or retire?

Smaller: a request source that fails rather than completes is described as not sending a GOAWAY, and by my reading that is what happens (onUpstreamFailure -> failStage), but there is no user.requestOut.sendError(...) case to pin it.

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