Repository navigation
feat(s3): route UploadPartCopy and ListParts (#532, #551) - #552
Merged
Merged
Conversation
Both operations were unroutable, and both for the same reason: parseS3Operation's object-level verb arms had drifted apart on when they test uploadId. PUT/DELETE/POST all tested it; GET alone did not, and PUT tested X-Amz-Copy-Source before it. A part copy was therefore claimed by CopyObject, which answered 200 with a correctly-shaped CopyPartResult while writing the destination object instead of storing a part — so HeadObject mid-upload reported a ContentLength real S3 never exposes, and Complete then failed with InvalidPart. ListParts reached GetObject and answered 404 NoSuchKey for an upload whose parts substrate had stored. UploadPartCopy now stores a part and leaves the destination key absent until Complete, honors x-amz-copy-source-range and the x-amz-copy-source-if-* preconditions. ListParts returns a ListPartsResult with max-parts/part-number-marker paging; zero parts is 200 with an empty list, and an unknown or wrongly-keyed uploadId is 404 NoSuchUpload. The router invariant is now stated once where all four verb arms are visible, since the arms drifting apart is what produced both bugs.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #532
Closes #551
Two S3 multipart operations were unroutable, and both for the same reason, so they ship as one review of
parseS3Operation's precedence order rather than two separate reorderings.The shared cause
The object-level verb arms had drifted apart on when they test
uploadId.PUT,DELETEandPOSTall tested it;GETalone did not, andPUTtestedX-Amz-Copy-Sourcebefore it. Since every multipart operation addresses the same key with the same verb as its general-object counterpart, nothing but the ordering distinguishes them.The invariant is now stated once in the router where all four arms are visible — a multipart request is identified by its
uploadId, and the general object-verb operation is a fall-through the router must reach only after every multipart test has failed. A comment on one arm would not have prevented the other.#532 —
UploadPartCopywas worse than filedMeasured against v0.89.0 on a live server, not inferred: the request answered
200with a correctly-shapedCopyPartResult, so nothing looked wrong — whileCopyObjectwrote the destination object. Ahead-objecton the destination mid-upload returnedContentLength 6291456, which real S3 never exposes, and thecomplete-multipart-uploadthat followed failedInvalidPartbecause no part had been stored.Now: stores a part, leaves the destination key absent until Complete, honors
x-amz-copy-source-rangeand thex-amz-copy-source-if-*preconditions, returnsETag/LastModifiedin aCopyPartResult. Copied and uploaded parts mix in one upload and a copied part's checksum is computed under the upload's algorithm, so Complete still assembles aCOMPOSITEobject checksum over the mixture.#551 —
ListPartshad no handler at allFound while reproducing #532.
GET /<bucket>/<key>?uploadId=…reachedGetObject→404 NoSuchKey, for an upload whose parts substrate had stored and could list. A caller polling its own upload could not tell an upload with parts from a key that does not exist.Now:
ListPartsResultwithmax-parts/part-number-markerpaging, the upload's storage class and checksum configuration, and each part's number,ETag, size,LastModifiedand checksum. Zero parts is200with an empty list, not a404. An unknownuploadId, or one addressed through the wrong key, is404 NoSuchUploadrather than theNoSuchKeyGetObjectanswered.Provenance
Two refusals are substrate's own choice, not the API model's:
x-amz-copy-source-rangeis400 InvalidArgument. The reference documents onlyInvalidRequest, and for an unsupported byte-range source. Unlike aGET's advisoryRangeheader — malformed is ignored, past-EOF is clamped — a copy-source range is part of the request's meaning, so a range substrate cannot honor is refused rather than silently turned into a different copy.bytes=0-is refused where aGETwould accept it: an open-ended range does not describe the extent of a part.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./...— all clean.Each gate fails before the fix. Reverting only the router ordering (leaving both handlers in place) turns every new test red, and #532's and #551's gates go red independently.
End to end against a live server, matching the plan's checks:
Mutation testing
Seven mutants, all CAUGHT, none survived — anchor-count asserted before applying,
gofmt -w && go vetgated, run under-race:DestinationKeyStaysAbsentListPartsdrops the ascending part-number sortReportsUploadedParts,PaginationloadUploadForstops confirming bucket/keyListParts_Errors/wrong_key, and an existing Complete testListParts_EmptyUploadx-amz-copy-source-rangeis ignoredSourceRangesubtestsIsTruncatednever reportedPaginationpart-number-markerignoredPaginationPlus the two router reversions above, which each go red independently.
Compatibility
A test that asserts a part copy writes the destination object, or that
GET ?uploadIdanswers404 NoSuchKey, will go red. That is the fix.CopyObjectandGetObjectwithout multipart parameters are unchanged, and two tests pin that explicitly.Refactors carried along
parseS3CopySourceis extracted soCopyObjectandUploadPartCopycannot drift on what a copy source means.loadUploadForandwritePartare extracted so all four multipart operations resolve an upload and store a part the same way — the mutation run confirms the sharedloadUploadForis covered by both the new tests and the existing Complete tests.