Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: start the loop over when handles are removed #16588

Closed
wants to merge 2 commits into from

Conversation

bagder
Copy link
Member

@bagder bagder commented Mar 6, 2025

Since more than one handle can be removed in a single call to multi_runsingle(), we cannot easily continue on the next node when a node has been removed since that node migth ALSO have been removed.

Reported-by: Philippe Antoine

bagder added 2 commits March 6, 2025 10:29
Since more than one handle can be removed in a single call to
multi_runsingle(), we cannot easily continue on the next node when a
node has been removed since that node migth ALSO have been removed.

Reported-by: Philippe Antoine
@@ -2619,6 +2620,12 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles)
if(result)
returncode = result;
}
if(num_alive != multi->num_alive)
Copy link

@piru piru Mar 6, 2025

Choose a reason for hiding this comment

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

I fear this might lead to some unforeseen complications due to restart leading multi_runsingle being called multiple times for early nodes in the llist.

One way to handle this would be to mark the nodes to be released with a flag and then only unlink and free them after the loop is done. This way the n pointer could never point to deallocated memory. It would require some other changes too, specifically skipping "going away" nodes, though. It'd also add extra iteration of the list when purging the going away nodes.

Other option would be to have some multi_runsingle version that'd maintain "next" pointer. If the node currently being released would be the "next" pointer, the pointer would be updated to be the next of the released node. Passing this pointer around would add fair bit of code though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since curl_multi_perform() can be called by an application at any time, and repeatedly, there really should not be any side-effect by this. We know what some applications do this as well, in for example PHP programs it has been common to not do any select/wait at all but just busy-call it and that generally works fine.

I agree that this should be done nicer to avoid the loop restart, but I would rather have us fix the immediate bug here in a simple way, then do the bigger work of doing this in a better way in a separate follow-up.

@bagder bagder closed this in a66ede5 Mar 6, 2025
@bagder bagder deleted the bagder/multi-loop branch March 6, 2025 15:11
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.

2 participants