Skip to content

multi: undo the counters when curl_multi_add_handle fails - #23526

Closed
Marti2203 wants to merge 1 commit into
curl:masterfrom
Marti2203:multi-add-timer-error
Closed

Marti2203 wants to merge 1 commit into
curl:masterfrom
Marti2203:multi-add-timer-error

Conversation

@Marti2203

@Marti2203 Marti2203 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

If the CURLMOPT_TIMERFUNCTION callback fails during curl_multi_add_handle(), the handle is removed from the transfer table again, but it stays counted in xfers_alive (and in the process and dirty sets). The running count from curl_multi_perform() then never gets back to 0, so a while(running) loop never ends, even after the handles that were actually added are done and removed.

This undoes those additions on that error path.

Unit test 3230 now also makes the timer callback fail during curl_multi_add_handle() and then checks that CURLMINFO_XFERS_RUNNING and CURLMINFO_XFERS_CURRENT are both 0. Without the change, the failed handle still counts as running.

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

@github-actions github-actions Bot added the tests label Oct 21, 2026
@testclutch

Copy link
Copy Markdown

Analysis of PR #23526 at ae95b7f4:

Test 1694 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 144 different CI jobs (the link just goes to one of them).

Generated by Testclutch

Comment thread tests/libtest/lib1694.c Outdated
global_init(CURL_GLOBAL_ALL);

multi_init(multi);
multi_setopt(multi, CURLMOPT_TIMERFUNCTION, t1694_timer);

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.

Is there a reaons these tests cannot be included in e.g. unit3230?

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.

No reason, thanks: I moved the checks into unit 3230 (a timer callback that fails during curl_multi_add_handle(), then CURLMINFO_XFERS_RUNNING and CURLMINFO_XFERS_CURRENT must both be 0) and removed lib1694/test1694. unit3230 fails without the lib/multi.c change and passes with it.

When the timer callback failed in curl_multi_add_handle(), the handle
was removed from the transfer table, but it stayed counted in
xfers_alive and in the process and dirty sets. The running handles
count reported by curl_multi_perform() then never reached zero, so an
application loop waiting for it never ended, even after removing all
the handles that were actually added.

Extend unit test 3230 to check the transfer counts after a failed add.
@Marti2203
Marti2203 force-pushed the multi-add-timer-error branch from 6422ca6 to 67ebec2 Compare October 21, 2026 13:50
@bagder bagder closed this in 191dc2a Oct 21, 2026
@bagder

bagder commented Oct 21, 2026

Copy link
Copy Markdown
Member

Thanks!

dkarpov1970 pushed a commit to dkarpov1970/curl that referenced this pull request Nov 18, 2026
When the timer callback failed in curl_multi_add_handle(), the handle
was removed from the transfer table, but it stayed counted in
xfers_alive and in the process and dirty sets. The running handles count
reported by curl_multi_perform() then never reached zero, so an
application loop waiting for it never ended, even after removing all the
handles that were actually added.

Extend unit test 3230 to check the transfer counts after a failed add.

Closes curl#23526

Backport notes:

- Dropped the unit3230.c extension (not in the release).

(cherry picked from commit 191dc2a)
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.

5 participants