Skip to content

return write error for short final chunk in File.ReadFrom - #670

Merged
puellanivis merged 1 commit into
pkg:masterfrom
christhomas:fix-readfrom-final-chunk-error
Oct 18, 2026
Merged

puellanivis merged 1 commit into
pkg:masterfrom
christhomas:fix-readfrom-final-chunk-error

Conversation

@christhomas

Copy link
Copy Markdown
Contributor

Fixes #668

When the reader ends part-way through the buffer, io.ReadFull returns io.ErrUnexpectedEOF together with the last bytes. That error was kept over the error from writing those bytes, and then turned into nil.

This follows the suggestion in the issue, with one difference: the unexpected EOF is only replaced when the write failed. Replacing it with a nil err2 as well would send the loop back to ReadFull after the reader has ended, which on a terminal waits for a second Ctrl-D. The "no error" case in the test checks for that.

@christhomas

Copy link
Copy Markdown
Contributor Author

The macOS failure isn't from this change. TestRequestStatVFS compares Bavail and Bfree for /, and the free block count changed between the two reads (expected: 0x17e697b, actual: 0x17e697c). That's #463, which #676 fixes. Could you re-run the job?

@puellanivis

Copy link
Copy Markdown
Collaborator

I kind of want to merge the flaky test fix, and then rebase… it’s a regular annoyance of having to hit rerun constantly. We should address it first, especially with so many PRs to merge.

@christhomas

Copy link
Copy Markdown
Contributor Author

if you merge 676 first, I can rebase this on top, then it should not be flakey anymore

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
@christhomas
christhomas force-pushed the fix-readfrom-final-chunk-error branch from cfe7b34 to 8634d51 Compare October 17, 2026 10:20
@puellanivis
puellanivis merged commit f79a590 into pkg:master Oct 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File.ReadFrom returns nil when writing the last, partial chunk fails

2 participants