Skip to content

http2: do not let a rate limit enlarge the stream window - #23472

Closed
Marti2203 wants to merge 1 commit into
curl:masterfrom
Marti2203:h2-limit-rate-window
Closed

Marti2203 wants to merge 1 commit into
curl:masterfrom
Marti2203:h2-limit-rate-window

Conversation

@Marti2203

Copy link
Copy Markdown
Contributor

With a download rate limit, cf_h2_get_desired_local_win() uses the rate limiter's available bytes as the HTTP/2 stream window whenever they fit in an int32. A high limit therefore gives a much larger window (up to ~2 GB instead of H2_STREAM_WINDOW_SIZE_MAX, 10 MiB).

With --limit-rate between ~1024M and 2047M this breaks the transfer: the window update exceeds the HTTP/2 maximum window size and nghttp2 rejects it, so the download fails immediately:

  $ curl --http2-prior-knowledge --limit-rate 1500M http://localhost:18443/big.bin -o /dev/null
  [1] nghttp2_submit_window_update() failed: Flow control error(-524)

At most 1000M works because the resulting window still fits, and at least 2048M works because the available bytes no longer fit an int32 and the default window is used.

This caps the rate-limited window at H2_STREAM_WINDOW_SIZE_MAX, so a rate limit can only reduce the window. Downloads at 1100M, 1500M, and 2047M now complete, and lower limits (5M to 100M) behave as before.
Test 1717 does an HTTP/2 GET with --limit-rate 1500M and fails without the change.

Side note: cf_h2_update_local_win() calls both nghttp2_session_set_local_window_size() and
nghttp2_submit_window_update() when growing the window, which raises it twice; that is why ~1 GB is already enough to overflow.
I left that unchanged since curl handles window updates manually.

Tested with nghttp2 1.40.0.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.

@github-actions github-actions Bot added the tests label Oct 18, 2026
@bagder
bagder requested review from icing and a balanced review from Copilot October 18, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix preserves lower-limit behavior and includes regression coverage, with no unresolved findings.

No open issues 🎉

What changed in this PR

Prevents high download rate limits from enlarging HTTP/2 stream windows beyond the existing 10 MiB cap.

Changes:

  • Caps rate-limited windows while preserving smaller limits.
  • Adds and registers a regression test using --limit-rate 1500M.
File Description
tests/​data/​test1717 Tests an HTTP/2 download with a high rate limit.
tests/​data/​Makefile.am Registers test 1717.
lib/​http2.c Caps the rate-limited stream window.

Review effort: Balanced

Comment thread tests/data/test1717 Outdated
# A rate limit above 1 GB/s used to set a stream window larger than the
# HTTP/2 window maximum allows after the update, failing the transfer.
<command option="no-include">
http://%HOSTIP:%HTTP2PORT/%TESTNUMBER --http2-prior-knowledge --limit-rate 1500M

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.

I question the usefulness of this auto-generated test. Can it be merged into
an existing one, or drop? We don't need to run this a million times, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I merged it into test 1700 (added --limit-rate 1500M) and dropped the new test in this PR. Can revert if you think it is not a good approach

@testclutch

Copy link
Copy Markdown

Analysis of PR #23472 at a9a78aec:

Test ../../tests/http/test_60_h3_proxy.py::TestH3Proxy::test_60_12_quic_session_resumption failed, but it has been permanently failing lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (4, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Generated by Testclutch

cf_h2_get_desired_local_win() used the rate limiter's available bytes
as the stream window whenever they fit an int32, so a high download rate
limit gave a much larger window than no limit at all (up to 2 GB instead
of H2_STREAM_WINDOW_SIZE_MAX). With --limit-rate between ~1024M and
2047M the window update then exceeded the HTTP/2 maximum and the
transfer failed at once with "Flow control error".

Cap the rate-limited window at H2_STREAM_WINDOW_SIZE_MAX, so that a rate
limit can only reduce the window.

Extend test 1700 with --limit-rate 1500M to verify.
@Marti2203
Marti2203 force-pushed the h2-limit-rate-window branch from a9a78ae to 60f353a Compare October 18, 2026 11:25
@bagder bagder closed this in c4b341c Oct 19, 2026
@bagder

bagder commented Oct 19, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

6 participants