Fix infinite loop in uploadChunked() when the transport never reads past the end of the stream - #160
Merged
Conversation
…ast the end of the stream
Member
Contributor
Author
|
Thank you Freek :) |
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.
Fixes #159.
uploadChunked()looped on$stream->eof(), but PHP only sets a stream's EOF flag once a read attempts to move past its end. Guzzle >= 7.15 ("Bound cURL upload reads to the declared Content-Length") and libcurl >= 8.7 clamp request body reads to the declared size and never read past the end, soeof()staysfalseafter the stream is fully consumed and the loop appends empty chunks forever.This PR terminates the loop on the read position (
tell() < getSize()) when the stream size is known, and keeps theeof()fallback for size-less streams (pipes viaPumpStream), which still terminate correctly because their final chunk read does attempt to move past the end.The regression test consumes each request body exactly to its declared size — the way Guzzle >= 7.15 / libcurl >= 8.7 behave — via a handler-stack middleware over a
MockHandler. Against the previous implementation it fails with an exhausted mock queue (the empty appends keep coming); with this change the upload finishes with the expected chunk sequence.Full analysis and an A/B reproduction (same host, only Guzzle version changed) are in #159.