Fix partsReader.WriteTo to close consumed parts on success#61
Merged
sendya merged 2 commits intoJun 1, 2026
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix the code for review comment in PR #60
Fix Jun 1, 2026
partsReader.WriteTo to close consumed parts on success
sendya
approved these changes
Jun 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes partsReader.WriteTo so that it consistently closes each part reader after it has been copied, preventing already-consumed parts from remaining unclosed (and later being skipped by Close() due to r.index having advanced).
Changes:
- Update
partsReader.WriteToto advancer.indexandClose()each consumed part on the success path (and before error branching), aligning lifecycle management withRead(). - Extend
TestPartsReader_WriteTo_AllSuccessto assert each underlying reader is closed exactly once and that a subsequent outerClose()does not double-close.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/iobuf/part_reader.go | Ensures each part is closed after io.Copy completes, even on the successful copy path. |
| pkg/iobuf/part_reader_test.go | Adds assertions verifying per-part closure on success and no double-close on outer Close(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
partsReader.WriteToadvancedr.indexwithout closing readers on the successful copy path, which could leave part readers unclosed and let a laterClose()skip them. This update alignsWriteTobehavior with the type contract by closing each part as it is fully consumed.Behavioral fix
pkg/iobuf/part_reader.go,WriteTonow closes each part reader afterio.Copy, regardless of whether the copy ended withnilorio.EOF.r.indexis advanced per consumed part before handling error branches, so reader lifecycle and index progression stay consistent.Targeted test coverage
pkg/iobuf/part_reader_test.go,TestPartsReader_WriteTo_AllSuccessnow asserts both readers are closed exactly once afterWriteTo.Close()does not double-close already consumed readers.