Repository navigation
cURL: Defer redirects in request_multiple() until all transfers finished - #1117
Draft
swissspidy wants to merge 1 commit into
Draft
swissspidy wants to merge 1 commit into
swissspidy wants to merge 1 commit into
Conversation
Responses were parsed as soon as their transfer finished, and parsing a redirect follows it with a new, blocking request. While that request ran, the other transfers of the batch were not serviced, but their timeouts kept running, so they could time out although their server had answered in time. Parse the responses that will be redirected once all transfers have finished instead. The redirects themselves are still followed one after the other, as before. Also stop instead of looping forever when `curl_multi_exec()` reports an error, and report the error for each unfinished transfer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5orPkSjWrCmXNcVAbH
This branch has not been deployed
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.
Pull Request Type
This is a:
Context
In
Transport\Curl::request_multiple(), a response is parsed as soon as its transfer finishes. Parsing a redirect follows it with a new, blocking request, from inside the multi loop. While that request runs, the other transfers of the batch are not serviced, but their timeouts keep running. They can then time out although their server answered in time.In a local test, a request to
/delay/1with a 2-second timeout failed with "Operation timed out after 4001 milliseconds with 0 bytes received", because the other request in the batch redirected to/delay/3. With this change, it succeeds.Found while reviewing concurrent requests for WordPress core: https://core.trac.wordpress.org/ticket/37459 and WordPress/wordpress-develop#13657. This is independent of the busy-loop fix in #1116, and the two branches merge cleanly.
Changelog: a redirect in a
Requests::request_multiple()batch no longer makes the other requests of the batch time out when using cURL.Detailed Description
Requests::parse_response():follow_redirectsis enabled, the request is blocking, and the status is 3xx other than 304, 305 and 306. Theirmultiple.request.completehook fires at that point too.curl_multi_exec()returns an error status, instead of looping forever. Each unfinished transfer gets aCurlException(typeCurlException::MULTI), and thetransport.internal.parse_errorandmultiple.request.completehooks fire for it.Quality assurance
testMultipleRedirectDoesNotStallOtherRequests(inBaseTestCase, so it runs for both transports) uses the test server's/redirect-toand/delay/nendpoints. It fails for cURL without the fix and passes with it.curl_multi_exec()return an error from a test on current PHP.developin that environment: it runs as root, and HTTPS goes through an intercepting proxy.Documentation
For new features:
examplesdirectory.docsdirectory.AI disclosure: this change was prepared with Claude Code.