Repository navigation
return the reader's io.ErrUnexpectedEOF from File.ReadFrom - #674
Merged
Merged
Conversation
When the reader ends part-way through the buffer, io.ReadFull returns io.ErrUnexpectedEOF with the last bytes. ReadFrom kept that error over the error from writing those bytes and then returned nil for it, so a refused final write was reported as success. Only replace it when the write failed, so the loop doesn't read r again after it has ended. Fixes pkg#668
ReadFrom filled its buffer with io.ReadFull and treated io.ErrUnexpectedEOF as the end of the data, because io.ReadFull returns it when the reader ends part way through the buffer. An io.ErrUnexpectedEOF from the reader itself was dropped as well. For example, copying an HTTP response body that was cut off into a File returned a nil error, and left a truncated file. Fill the buffer with a loop that returns the reader's error unchanged, and only treat io.EOF as the end of the data. Fixes pkg#673
christhomas
force-pushed
the
fix-readfrom-source-error
branch
from
October 17, 2026 10:20
3d29963 to
e5604b2
Compare
puellanivis
approved these changes
Oct 19, 2026
Comment on lines
+2122
to
+2125
| // readFull reads from r into b until b is full or r returns an error. | ||
| // Unlike io.ReadFull, it returns the error from r unchanged. io.ReadFull | ||
| // turns an io.EOF after a partial read into io.ErrUnexpectedEOF, which | ||
| // can't be told apart from an io.ErrUnexpectedEOF returned by r itself. |
Collaborator
There was a problem hiding this comment.
While there are plenty of comments that don’t follow semantic breaking, we should generally strive to make sure that new comments do.
Contributor
Author
|
Updated the comment to explain the semantic difference directly: io.ReadFull converts EOF after a partial read to io.ErrUnexpectedEOF, so that result cannot be distinguished from a reader that returned io.ErrUnexpectedEOF itself. The comment now uses line breaks at those related points to make the distinction easier to scan. |
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 #673
This builds on #670, which changes the same lines, so its commit is included here. Only the last commit is new. I'll rebase once #670 is merged, or merge the two if you prefer one PR.
ReadFromusedio.ReadFullto fill its buffer and treatedio.ErrUnexpectedEOFas the end of the data. That also hid anio.ErrUnexpectedEOFreturned by the reader itself, such as a cut-off HTTP body. Both paths now fill the buffer with a small loop that returns the reader's error unchanged, and onlyio.EOFends the copy without an error.The test fails without the change for a short chunk, a full chunk and the concurrent path. It passes with
-race,-integrationand-testserver.