Skip to content

setopt: keep a paused transfer paused when the speed limit is changed - #23462

Closed
1rhino2 wants to merge 2 commits into
curl:masterfrom
1rhino2:rlimit-keep-pause
Closed

1rhino2 wants to merge 2 commits into
curl:masterfrom
1rhino2:rlimit-keep-pause

Conversation

@1rhino2

@1rhino2 1rhino2 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Curl_rlimit_init() clears the limiter's blocked flag and the pause state of the recv and send side is derived from that flag, so setting CURLOPT_MAX_RECV_SPEED_LARGE (or the send one) on a paused transfer unblocked it with the client writer still paused: the transfer kept reading into the pause buffer and a later curl_easy_pause(CURLPAUSE_CONT) was a no-op, the transfer never finished. Reproduced on 8.23.0 with a small multi program that pauses from the write callback, sets the recv speed 300 ms later and unpauses 400 ms after that: with the setopt the transfer sits until CURLOPT_TIMEOUT with 32 KB delivered, without it 2.2 MB arrive. This re-applies the block after the init when that side is paused; the same program then completes like the control, the full suite is unchanged.

Curl_rlimit_init() clears the blocked flag of the rate limiter, and the
recv and send pause state is derived from that flag. Setting
CURLOPT_MAX_RECV_SPEED_LARGE or CURLOPT_MAX_SEND_SPEED_LARGE on a paused
transfer therefore unblocked it while the client writer or reader was
still paused: the transfer went on reading into the pause buffer and a
later curl_easy_pause(CURLPAUSE_CONT) was a no-op, so the transfer never
finished (or hit the pause buffer limit).

Re-apply the block after the init when that side is paused.
@testclutch

Copy link
Copy Markdown

Analysis of PR #23462 at f61ecd3a:

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

@icing

icing commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Keeping the blocked state on a change is a good idea. The proposed solution here is a a bit hacky, though. I believe we need a "change" method for ratelimits.

Change the rates of a limiter in place instead of re-initializing it,
so a transfer that is paused when CURLOPT_MAX_RECV_SPEED_LARGE or
CURLOPT_MAX_SEND_SPEED_LARGE is set stays paused and the time already
accounted for is kept. Replaces the re-applied block from the previous
commit.
@1rhino2

1rhino2 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

fair, redone as a Curl_rlimit_change() in ratelimit.c that sets the new rate and burst in place, caps the tokens at the new rate and leaves ts and blocked alone, and setopt now calls that instead of init for both speed options. second commit on the branch, the first one with the re-applied block is gone from the net diff so squash will do. the pause repro completes again and the 13 limit-rate and pause tests pass, full suite is running here; Curl_rlimit_init() has no caller left in lib now, i left it in place in case you want it, say if it should go.

@bagder bagder closed this in a8b9f53 Oct 19, 2026
@bagder

bagder commented Oct 19, 2026

Copy link
Copy Markdown
Member

Thanks!

dkarpov1970 pushed a commit to dkarpov1970/curl that referenced this pull request Nov 18, 2026
Curl_rlimit_init() clears the blocked flag of the rate limiter, and the
recv and send pause state is derived from that flag. Setting
CURLOPT_MAX_RECV_SPEED_LARGE or CURLOPT_MAX_SEND_SPEED_LARGE on a paused
transfer therefore unblocked it while the client writer or reader was
still paused: the transfer went on reading into the pause buffer and a
later curl_easy_pause(CURLPAUSE_CONT) was a no-op, so the transfer never
finished (or hit the pause buffer limit).

Re-apply the block after the init when that side is paused.

Closes curl#23462

Backport notes:

- Kept the release's burst rate (equal to the rate); only replaced
  Curl_rlimit_init() with Curl_rlimit_change().

(cherry picked from commit a8b9f53)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants