Close the upload stream under a parked curl read - #296
Merged
Merged
Conversation
The test closes the handle curl uploads from, from another coroutine, between two of curl's reads: the transfer is throttled so that no read is in flight at that moment, which is the state in which the reactor holds no pin of its own and the subscription has to keep the io alive by itself. Before the php-src change it is a heap-use-after-free under ASAN in curl_async_read_state_free(). The close is ordered by the progress callback rather than by a count of scheduler turns, and the wait is bounded so that a build whose progress callback never reports says so instead of hanging. #295
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Below libcurl 8.11.1 curl_async_read does a synchronous read(2): curl_exec pushes the whole body before the closing coroutine gets a turn, so the close lands after the transfer and the assertion reads "completed" instead of "aborted". The subscription the test covers is not built there either -- it sits behind the same version guard. Measured against libcurl 8.5.0, the version the Linux CI builds from source, and 7.87.0, the declared minimum. #295
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.
Covers #295. Pairs with true-async/php-src#34, which carries the fix.
The test closes the handle curl uploads from, from a second coroutine, between two
of curl's reads.
CURLOPT_MAX_SEND_SPEED_LARGEspreads the upload over seconds sothat the close lands with no read in flight — the state in which the reactor holds
no pin of its own on the stream's IO and the subscription has to keep it alive by
itself. Before the php-src change:
Ordered by the progress callback rather than by a count of scheduler turns, and
bounded by a deadline that says out loud when it gave up, following
070-read_takes_only_its_completion.phpt.The ASAN run needs
USE_ZEND_ALLOC=0: the io is freed through ZendMM, and withoutthat the sanitizer never sees the free.
The second half of the php-src change, #294, has no test here. The dangling event
pointer of a
CURLFileread state was observed directly, with a read in flight, byinstrumenting the event's destructor, but no script made a completion land in the
window between that destructor and libcurl's
free_cb— ten attempts, including afifo source, which does not work for
CURLFilebecause the part's length comes fromstat, and a single-threadUV_THREADPOOL_SIZEwith eight concurrent uploads. TheCHANGELOG entry says so.
Checks
ext/async/tests/curlunder ASAN — 68 passed, 0 failed.ext/async/tests— 1194 passed, 0 failed.fuzzy-tests/_generated— 724 passed, 0 failed.