fix: broken get and replace for s3 client - #21163
Merged
Merged
Conversation
trevorwhitney
approved these changes
Mar 13, 2026
loki-gh-app Bot
pushed a commit
that referenced
this pull request
Mar 16, 2026
(cherry picked from commit e6abd15)
This was referenced Jun 23, 2026
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.
What this PR does / why we need it:
When GetAndReplace callbacks return opaque io.ReadCloser wrappers (such as io.NopCloser), objstore.TryToGetSize cannot determine the content size, causing minio-go to use a multipart upload path that silently reconstructs PutObjectOptions before CompleteMultipartUpload, dropping customHeaders and, therefore, the If-Match conditional write header. S3 then accepts the upload unconditionally, allowing a stale-ETag write to overwrite a newer version of the object.
To fix it, I have added sizedGetAndReplaceBucket, which wraps the caller's callback inside GetAndReplace and buffers the returned reader when its size is unknown, replacing it with an objstore.NopCloserWithSize-wrapped bytes.Reader. This gives minio-go a known content length, forcing the single-part PUT path where If-Match is preserved end-to-end.
GetAndReplace is only used to update TOC files, which are not that large, so switching them to a single-part upload should not cause any issues. We can try to fix the issue upstream or change the reader interface to match what objstore.TryToGetSize handles.