fix(h2): validate maxConcurrentStreams and read settings.initialWindowSize - #5608
Open
marko1olo wants to merge 1 commit into
Open
fix(h2): validate maxConcurrentStreams and read settings.initialWindowSize#5608marko1olo wants to merge 1 commit into
marko1olo wants to merge 1 commit into
Conversation
…wSize The h2 option namespacing in nodejs#5498 left two wires crossed. Neither has shipped yet: nodejs#5498 landed after the v8.9.0 bump, so both are on main only. The guard for `h2Options.maxConcurrentStreams` tests `h2Options.connectionWindowSize`, copied from the block below it. With `maxConcurrentStreams` set and `connectionWindowSize` absent, `Number.isInteger(undefined)` is false and the negation makes the condition true, so `new Client(url, { h2Options: { maxConcurrentStreams: 10 } })` throws `h2Options.maxConcurrentStreams must be a positive integer, greater than 0` for the integer 10. Adding an unrelated `connectionWindowSize` makes the same call pass. It fails open the other way too: `{ maxConcurrentStreams: 'not-a-number', connectionWindowSize: 65535 }` is accepted. Through an Agent or Pool it is worse, because clients are built lazily — construction succeeds and then every request rejects with that message, including over a plain HTTP/1.1 origin where no h2 session exists. `h2Options.settings.initialWindowSize` is the documented shape and is what the validation above checks, but the session options read `h2Options.initialWindowSize`, so the documented option was validated and then dropped, and an undocumented flat one was honoured instead. test/http2-options.js covers both: it fails on the current code and passes here. Signed-off-by: marko1olo <marko1olo@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5608 +/- ##
==========================================
- Coverage 93.50% 93.49% -0.02%
==========================================
Files 110 110
Lines 38303 38303
==========================================
- Hits 35816 35812 -4
- Misses 2487 2491 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This relates to...
A regression from #5498, which landed after the v8.9.0 bump, so both halves below are on
mainand have not shipped yet.Rationale
The h2 option namespacing left two wires crossed.
1.
h2Options.maxConcurrentStreamsis validated against the wrong property. The guard testsh2Options.connectionWindowSize:It is the block below it, copied. With
maxConcurrentStreamsset andconnectionWindowSizeabsent,Number.isInteger(undefined)isfalseand the negation makes the condition true, so a valid integer throws. It also fails open in the other direction.Through
AgentorPoolit is worse, because clients are created lazily: construction succeeds and then every request rejects with that message, including against a plain HTTP/1.1 origin where no h2 session is ever negotiated.2.
h2Options.settings.initialWindowSizeis validated and then dropped. The validation checksh2Options.settings?.initialWindowSize, which matchesdocs/docs/api/Client.md, but the session options readh2Options?.initialWindowSize, so the documented option never reaches the session and an undocumented flat one is honoured instead.{ h2Options: { settings: { initialWindowSize: 131072 } } }leavessessionOptions.initialWindowSizeundefined.Changes
Two lines in
lib/dispatcher/client.js: validatemaxConcurrentStreamsagainst itself, and readsettings.initialWindowSizewhere the session options are built. I keptNumber.isIntegerrather than the loosertypeof !== 'number'used by the legacy branch, because it is what the error message promises.test/http2-options.jscovers both, readingclient[kHTTP2Options]directly. It fails 0/2 on currentmainand passes 2/2 here.npm run test:h2is green.Features
Bug Fixes
Status