feat: handle parallel chunk upload assembly race in Local and S3 devices#163
feat: handle parallel chunk upload assembly race in Local and S3 devices#163TorstenDittmann merged 1 commit intomainfrom
Conversation
bedcdc3 to
b9a672f
Compare
Greptile SummaryThis PR adds race-condition guards for parallel chunk upload assembly in the Local and S3 devices: a Confidence Score: 3/5Mergeable for the Local device path; the S3 path still has unresolved P1 issues from prior review rounds that should be addressed before shipping. No new P1s found in this pass, but pre-existing P1s from earlier rounds — S3 headers left mutated on the early-return path, and the active $uploadId multipart upload abandoned without abort — remain unresolved in the current diff. Multiple unresolved P1s pull the score below the 4/5 ceiling. src/Storage/Device/S3.php — header restore is unreachable on the early-return path and the multipart upload is left orphaned. Important Files Changed
Reviews (6): Last reviewed commit: "feat: handle parallel chunk upload assem..." | Re-trigger Greptile |
b9a672f to
8c524af
Compare
b97e42e to
fb3ec61
Compare
f1ee72f to
184f505
Compare
184f505 to
65b3b3e
Compare
Summary
This PR adds race-condition handling for parallel chunk uploads across all storage devices.
Problem
When two requests upload the final missing chunks in parallel, both can observe that all chunks are present and attempt to assemble/complete the file simultaneously. The loser would previously throw an error even though the file is fully assembled.
Local Device
file_exists($path)guard at the start ofjoinChunks()— if the final file already exists, another request already assembled it, so return silently.file_exists($path)guard in therename()failure handler — ifrename()fails because the destination already exists, clean up the temp assembly file and return silently instead of throwing.S3 Device (and all S3-compatible adapters: AWS, Backblaze, DO Spaces, Linode, Wasabi)
$this->exists($path)guard beforecompleteMultipartUpload()— if the final object already exists, another request already completed the multipart upload, so return the chunk count silently.Tests
testParallelChunkUpload()toLocalTest.phpto verify that callingjoinChunks()when the file already exists does not throw and does not corrupt the file.Backwards Compatibility
Fully backwards compatible. The changes only affect error paths when assembly/completion races occur. No public API signatures are changed.
Related