Fix chunk index mismatch between getSliceChunkFile and checkChunkSize#50
Merged
Fix chunk index mismatch between getSliceChunkFile and checkChunkSize#50
Conversation
In getContents, checkChunkSize was called with idx (reqChunks[from]) but the chunk file was opened for availableChunks[index]. These can be different values, causing incorrect size validation — especially for the last chunk which has a different (smaller) expected size. Fixes omalloc/tavern#issue Co-authored-by: sendya <5404542+sendya@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix mismatch in getSliceChunkFile and checkChunkSize
Fix chunk index mismatch between getSliceChunkFile and checkChunkSize
Mar 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an incorrect chunk-index being passed to checkChunkSize in the caching middleware, which could trigger false “size mismatch” errors when the anchor chunk found via binary search differs from the originally requested chunk (notably for a partial last chunk).
Changes:
- Pass
availableChunks[index](the chunk actually opened) intocheckChunkSizeingetContents. - Add a regression test covering the partial last-chunk mismatch scenario.
- Minor related refactors/adjustments (iobuf helper/parameter rename) and module dependency bumps.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| server/middleware/caching/internal.go | Fixes the checkChunkSize index mismatch when using an anchor chunk; adjusts how the combined reader is constructed. |
| server/middleware/caching/caching_chunkpart_test.go | Adds a test reproducing the last-chunk partial size mismatch scenario. |
| pkg/iobuf/part_reader.go | Renames the PartsReadCloser parameter to clarify “optional closer” intent (no functional change). |
| pkg/iobuf/closer_reader.go | Adds NopCloser() helper used by the caching code path. |
| go.mod | Bumps multiple dependency versions. |
| go.sum | Updates checksums corresponding to the dependency bumps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| // get all hit block | ||
| availableChunks := c.getAvailableChunks() | ||
| slices.SortFunc(availableChunks, func(i, j uint32) int { | ||
| return int(i - j) |
Comment on lines
7
to
+29
| @@ -26,50 +26,50 @@ require ( | |||
| github.com/shirou/gopsutil/v4 v4.26.1 | |||
| github.com/stretchr/testify v1.11.1 | |||
| go.uber.org/zap v1.27.1 | |||
| golang.org/x/sync v0.18.0 | |||
| golang.org/x/sync v0.20.0 | |||
Comment on lines
+14
to
+23
| type nopCloser struct { | ||
| } | ||
|
|
||
| func NopCloser() io.Closer { | ||
| return &nopCloser{} | ||
| } | ||
|
|
||
| func (nopCloser) Close() error { | ||
| return nil | ||
| } |
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.
checkChunkSizewas called withidx(reqChunks[from]) but validated against a file opened foravailableChunks[index]. These differ when the anchor chunk found via binary search isn't the originally requested chunk — causing false size-mismatch errors, particularly for the last chunk which has a smaller expected size.availableChunks[index]tocheckChunkSizeto match the chunk file that was actually openedTest_getContents_lastChunkSizeMismatch— reproduces the bug using a partial last chunk (100KB vs 512KB block size) where the requested and anchor chunk indices divergeOriginal prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.