Repository navigation
fix(s3): finalize multipart uploads with exactly the selected parts - #14601
Conversation
|
Review complete. No issues found — approved ✅. This change deletes the
Reviewed commit: 075be7e |
🟢 Tier S · Ready to mergeThis change finalizes S3 multipart uploads using the submitted part count and restricts device metadata to the submitted parts. It also adds signed-request end-to-end coverage for small single-part uploads, selected-part completion, and invalid completion requests.
📂 Walkthrough · 2
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…ing part
CompleteMultipartUpload with one part uploaded an empty part 2 before
finalizing. On S3 storage devices that turns part 1 into a non-final
part, so any single-part upload under 5 MiB failed with EntityTooSmall
("Your proposed upload is smaller than the minimum allowed object
size"). files-sdk resumable uploads hit this for every file smaller
than one part.
Both devices finalize a prepared one-chunk upload directly (Local joins
the single part, S3 completes with it), so finalize with the selected
part count instead.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017yqpHr9VatgPv6T5nEXmrB
Co-Authored-By: Torsten Dittmann <[email protected]>
… upload S3 lets CompleteMultipartUpload select fewer parts than were uploaded. The S3 storage device completes its backend upload with every part in the device metadata, so an object completed with parts 1-2 of 3 stored part 3's bytes too, while its size and ETag counted only the selected parts. Keep only the selected parts before finalizing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017yqpHr9VatgPv6T5nEXmrB Co-Authored-By: Torsten Dittmann <[email protected]>
Adds SigV4-signed e2e tests for CompleteMultipartUpload: a single part smaller than 5 MiB, completion with a subset of the uploaded parts, and the failure cases (completed upload, wrong ETag, parts not starting at 1). Tagged `s3` so the S3 Storage lane runs them against MinIO, where both bugs fixed on this branch failed with EntityTooSmall. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017yqpHr9VatgPv6T5nEXmrB Co-Authored-By: Torsten Dittmann <[email protected]>
2281515 to
5e0424e
Compare
What does this PR do?
Someone reported that S3 multipart uploads failed when they tested them with files-sdk. I ran files-sdk 3.1.1 (
@aws-sdk/client-s3/@aws-sdk/lib-storage3.1152.0) against a local Appwrite, on both the Local storage device and the S3 storage device (with a RustFS backend). This PR fixes two bugs in how the gateway finalizes multipart uploads. Both appear only on the S3 storage device, which is what Cloud uses.1. Single-part uploads failed with
EntityTooSmall. WhenCompleteMultipartUploadreceived one part, the gateway uploaded an empty part 2 before finalizing. That made part 1 a non-final part, and S3 backends reject non-final parts under 5 MiB withEntityTooSmall. files-sdk resumable uploads (control: new UploadControl()) send one part for any file smaller than a part, so all of those failed. The padding isn't needed, because both devices already finalize a prepared one-chunk upload:Local::finalize()joins the single part (whole = false), andS3::finalize()completes with it. The gateway now finalizes with the selected part count, anduploadEmptyMultipartFinalChunk()is removed.2. Unselected parts were stored (found by review). S3 allows completing with fewer parts than were uploaded. The S3 device completed its backend upload with every part in its metadata, so the stored bytes included parts the client did not select, while the recorded size and ETag counted only the selected ones. The gateway now limits the device parts to the selected part numbers before finalizing.
Tests.
tests/e2e/Services/Storage/S3CustomServerTest.phpadds the first e2e tests for the S3 gateway. They send SigV4-signed requests to/v1/s3and cover:They are tagged
s3, so the Storage lane runs them on the Local device and the S3 Storage lane runs them on MinIO.Not changed here (needs a decision): Swoole's
package_max_lengthinapp/http.phpis 12 MiB. Any S3 request body above that, whether a singlePutObjector anUploadPartwith a largerpartSize, gets a bare 413 from Swoole with no S3 XML error, and clients show it asUnknownError. The files-sdk docs and CLI examples use--part-size 16777216(16 MiB), and that fails every part. The default 5 MiB parts work. Fixing this means raising the global limit or streaming request bodies, which has memory trade-offs, so it is left out of this PR.Test Plan
New e2e tests (
S3CustomServerTest):main'sBase.php, S3 deviceEntityTooSmall("Your proposed upload is smaller than the minimum allowed object size")files-sdk's
s3()adapter against/v1/s3. Each case downloads the object back and checks it byte for byte:multipart: true, 12 MiB (3 × 5 MiB parts)ReadableStream, 12 MiBUploadControl, 12 MiBUploadControl, 1 B / 1 MB (single part)EntityTooSmallmultipart: { partSize: 16 MiB }Static checks on the changed files:
pint --testwith the repopint.json: cleanphpstan analyse -c phpstan.neon: cleantests/tools/rector.php: cleanphpunit tests/unit/Platform/Modules/S3: OK (41 tests)Related PRs and Issues
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_017yqpHr9VatgPv6T5nEXmrB