chore: multipart upload ETag normalization and add debug logging #9
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.
Multipart uploads fail intermittently because S3 returns quoted ETags (
"abc123") butCompleteMultipartUploadexpects unquoted values. The existing mutex protection for the parts slice was already correct.Changes
ETag normalization: Trim quotes from S3 ETag responses before storing in parts array
Debug logging: Added logging when appending parts and before completion to aid diagnosis of future failures
CompleteMultipartUploadImport: Added
stringspackage for ETag processingAlternative approaches considered
The minimal mutex+trim approach fixes the immediate ETag mismatch with lowest risk.
Original prompt
Problem summary
Users report intermittent failures during multipart uploads with logs like "error uploading file to bucket: multipart upload failed". Investigation shows the multipart upload implementation (gen3-client/g3cmd/upload-multipart.go) appends to a shared parts slice from multiple goroutines without synchronization, which is a data race and can lead to corrupted or missing part entries. Additionally, ETag values returned by S3-like services are often quoted (e.g., ""abc123""), and the code does not normalize/trims ETag quotes before sending the CompleteMultipartUpload request, which can cause completion to fail.
Goal
Create a small, focused patch that:
Files to change
").Change rationale
Patch requirements
Other alternatives (analysis)
Below is a writeup of a more defensive rework that reduces locking contention and adds validation before completing the multipart upload.
Pros: reduces lock contention and potential for contention under many small parts; cleaner semantics.
Cons: requires more code changes and memory for per-worker buffers, but memory is proportional to number of parts, not chunk size.
Pros: simple to reason about; avoids locks entirely.
Cons: requires channel read loop and coordination to close the channel when all workers are done.
Why the minimal mutex+ETag trim is chosen
PR contents & testing notes
Modify gen3-client/g3cmd/upload-multipart.go to:
")Run
go veta...This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.