Skip to content

Require initial non-ACK SETTINGS in HTTP/2 connections - #1457

Merged
pjfanning merged 2 commits into
apache:mainfrom
He-Pin:test/http2-first-settings-contract
Nov 18, 2026
Merged

pjfanning merged 2 commits into
apache:mainfrom
He-Pin:test/http2-first-settings-contract

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

RFC 9113 section 3.4 requires each peer's connection preface to start with a SETTINGS frame, not a SETTINGS acknowledgment. The client and server previously continued processing ordinary control frames after an initial SETTINGS ACK.

Modification

  • Enable initial-SETTINGS validation explicitly for connection framing, leaving generic frame parsing unchanged by default.
  • Check the first wire frame before unknown frame types can be discarded, and retain the initial-frame state until the complete frame has been parsed.
  • Terminate this specific preface error through the existing PROTOCOL_ERROR connection-error path. Other protocol-error and normal EOF handling are unchanged.
  • Make initial-SETTINGS validation a default parameter of the internal Http2FrameParsing constructor (no separate three-argument constructor). No user-facing docs change, since this is standard RFC behaviour that users can't configure.
  • Add focused client/server regressions and legal empty, nonempty, fragmented, subsequent-ACK, early outgoing request HEADERS, and generic-parser controls.

Result

Both endpoints reject an initial SETTINGS ACK rather than acknowledging a subsequent PING. Valid connections still send their own preface without waiting for the peer's preface. Generic parser consumers can continue parsing standalone frames.

Tests

  • 29 distinct focused tests pass: 10 new connection/generic-parser cases, 15 existing server graceful-shutdown/max-connection-age cases, and 4 ordinary SETTINGS/PING parser cases.
  • Before the fix, both initial-ACK regressions observed an actual PING acknowledgment; afterward both observe PROTOCOL_ERROR GOAWAY followed by connection completion.
  • Scoped OrganizeImports, Scalafmt checks, generated ASF header and cross-Scala header checks pass.
  • +http-core/mimaReportBinaryIssues passes on Scala 2.13.18 and 3.3.9.
  • docs/paradox passes (existing unrelated duplicate-anchor warnings).
  • git diff --check passes. Full suites/aggregate validation and CI were not run; verification used the listed focused scopes.

References

  • RFC 9113, section 3.4
  • None - independent implementation based on the HTTP/2 connection-preface contract.

@pjfanning pjfanning added this to the 2.1.0 milestone Nov 15, 2026

@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.

Thanks, the parser change looks right. The check runs on the frame header before unknown frame types are dropped, and it's only cleared after the whole first frame has parsed, so a fragmented SETTINGS payload retries correctly. Failing the stage gives GOAWAY with last-stream-id 0 via errorHandling, which is accurate here since no streams can have been processed. A few points on the tests and docs:

  1. The ACK case accepts two outcomes. The invalid-preface branch passes on either a PROTOCOL_ERROR GOAWAY or a bare completion, and logs which one it saw with info. With InvalidConnectionPreface going through failStage → Http2Blueprint.errorHandling, the behaviour is deterministic: a GoAwayFrame(0, PROTOCOL_ERROR) followed by completion. Could the test require exactly that? As written, a regression that drops the GOAWAY would still pass. The OnError branch's message ("requires provenance review before classification") could also just be a plain failure.
  2. Minor: imports. Http2FirstSettingsSpec spells out org.apache.pekko on every import. Pekko code usually does import org.apache.pekko once and then import pekko.http....
  3. Minor: the extra constructor. Http2FrameParsing is private[http2] and @InternalApi, so keeping a separate 3-argument constructor next to the new default parameter isn't needed for compatibility. Either one alone would do.
  4. Docs. The two identical "Connection preface" sections in the client and server http2.md describe RFC behaviour users can't configure. I'd drop them.

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
Both endpoints continued ordinary control-frame processing after an initial
SETTINGS acknowledgment, contrary to RFC 9113 section 3.4.

Modification:
Enable connection-only first-frame validation while retaining generic parser
behavior and constructor compatibility. Terminate this specific preface error
through the existing protocol-error path and retain the focused tests.
Omit the duplicated client/server protocol documentation as requested in review.

Result:
Preserve the existing implementation and tests without repeating protocol
requirements in the user documentation. Other review feedback remains pending.

Tests:
- git diff --check passed for the documentation-only revision.
- Runtime and test blobs are identical to e976cdc.
- Not run - docs only revision. docs/paradox not run: JAVA_HOME is unset and
  javac is unavailable; no toolchain changes were made.
- Original PR records 29 focused tests and scoped formatting/import, header,
  MiMa and documentation checks. These historical results were not rerun or
  independently verified for this revision.

References:
Refs apache#1457; RFC 9113 section 3.4; documentation review by pjfanning.
@He-Pin
He-Pin force-pushed the test/http2-first-settings-contract branch from e976cdc to 096b413 Compare November 17, 2026 15:35
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
Require the connection preface contract while preserving generic frame parsing.
Address the reviewer-requested test import convention and omit duplicated docs.

Modification:
Retain the existing connection-only first-frame validation and tests.
Use the org.apache.pekko root import followed by pekko-prefixed test imports.
Omit duplicated client/server protocol documentation.

Result:
The test imports follow repository convention without changing test behavior.
Constructor compatibility and protocol-policy review points remain unchanged.

Tests:
- Cached Scalafmt 3.11.5 reports the revised test unchanged.
- git diff --check passed; changes from the reviewed head are imports only.
- Exact previous head 096b413 has successful
  Headers, Scalafmt, and Validate and test workflows.
- Tests and full compilation were not rerun for this import-only revision;
  javac is unavailable. No protocol-error scenarios were executed.

References:
Refs apache#1457; RFC 9113 section 3.4; pjfanning review.
@He-Pin
He-Pin force-pushed the test/http2-first-settings-contract branch from 096b413 to 2505857 Compare November 17, 2026 17:38
@He-Pin
He-Pin requested a review from pjfanning November 17, 2026 17:47
He-Pin and others added 2 commits November 17, 2026 19:31
Motivation:
Require the connection preface contract while preserving generic frame parsing.
Address the reviewer-requested test import convention and omit duplicated docs.

Modification:
Retain the existing connection-only first-frame validation and tests.
Use the org.apache.pekko root import followed by pekko-prefixed test imports.
Omit duplicated client/server protocol documentation.

Result:
The test imports follow repository convention without changing test behavior.
Constructor compatibility and protocol-policy review points remain unchanged.

Tests:
- Cached Scalafmt 3.11.5 reports the revised test unchanged.
- git diff --check passed; changes from the reviewed head are imports only.
- Exact previous head 096b413 has successful
  Headers, Scalafmt, and Validate and test workflows.
- Tests and full compilation were not rerun for this import-only revision;
  javac is unavailable. No protocol-error scenarios were executed.

References:
Refs apache#1457; RFC 9113 section 3.4; pjfanning review.
Motivation:
The initial SETTINGS ACK case accepted either a PROTOCOL_ERROR GOAWAY or a
bare completion, so a regression that dropped the GOAWAY would still pass.
The extra three-argument Http2FrameParsing constructor is not needed for
this internal class.

Modification:
Expect exactly GoAwayFrame(0, PROTOCOL_ERROR) followed by completion, and
remove the redundant constructor.

Result:
The test pins the connection error the server and client actually send.

Tests:
- sbt "http2-tests/testOnly ...Http2FirstSettingsSpec": 10 passed
- sbt "http-core/mimaReportBinaryIssues": passed

References:
Refs apache#1457 review
@pjfanning
pjfanning force-pushed the test/http2-first-settings-contract branch from 2505857 to 8911e11 Compare November 17, 2026 18:34
@pjfanning

Copy link
Copy Markdown
Member

I rebased this onto main and pushed a separate commit (8911e11). The invalid-preface case now requires exactly GoAwayFrame(0, PROTOCOL_ERROR) followed by completion. I also removed the extra three-argument Http2FrameParsing constructor; http-core/mimaReportBinaryIssues still passes. Feel free to revert anything you don't agree with.

@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.

LGTM

@pjfanning
pjfanning merged commit a5dd936 into apache:main Nov 18, 2026
6 checks passed
He-Pin added a commit that referenced this pull request Nov 28, 2026
Motivation:
The client and server startup tests confirm the initial SETTINGS frame type,
but do not check that a non-default concurrent stream limit reaches the peer.

Modification:
Use different positive limits for the two endpoints in the existing nonempty
SETTINGS cases and assert the single advertised value on the decoded first
outbound frame. Leave other settings and the remaining scenarios unchanged.

Result:
The tests catch a missing, duplicated, or defaulted advertisement without
opening HTTP/2 request streams or changing production code.

Tests:
- JDK 17, Scala 2.13.18 and 3.3.9: both exact-name nonempty startup tests
  passed on each axis using unchanged main production classes.
- Scoped scalafmt and git diff --check passed. Full sbt was not run.

References:
Refs #1457; RFC 9113 section 6.5.2.
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