Fix presigned url multipart download for empty objects#6952
Open
jencymaryjoseph wants to merge 1 commit into
Open
Fix presigned url multipart download for empty objects#6952jencymaryjoseph wants to merge 1 commit into
jencymaryjoseph wants to merge 1 commit into
Conversation
e037d5d to
10e45b1
Compare
56dc8cb to
3d21f24
Compare
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.
Motivation and Context
Presigned URL multipart downloads fail with HTTP 416 (Range Not Satisfiable) when downloading zero-byte objects. The multipart subscriber sends Range: bytes=0-8388607 to request the first part, but for a zero-byte object there are no bytes in that range, so S3 returns 416 per the HTTP spec.
Normal (non-presigned) multipart downloads don't have this issue because they use partNumber=1 as a query parameter. S3 treats this differently — it returns 200 with Content-Length: 0 for empty objects, because "give me part 1" is valid even when the part is empty.
The difference is the mechanism: Range headers require the byte range to exist (fails for empty objects), while partNumber returns the part content regardless (succeeds with empty body).
Modifications
When the first range request returns 416, the helper catches it and falls back to a non-range GET using the same presigned URL. The non-range GET succeeds for empty objects (returns 200 with Content-Length: 0), and the response flows through the normal transformer path — creating the file and returning full metadata.
A marker exception (
EmptyObjectRangeNotSatisfiableException) distinguishes 416 on the first request (empty object, safe to fallback) from 416 on subsequent requests (real error that should propagate). Subscribers wrap the 416 in this marker only on the first request. The helper only triggers the fallback for this marker — all other errors propagate normally.PresignedUrlDownloadHelper: Added 416 fallback logic in downloadObject(), extracted doMultipartDownload(), added isRangeNotSatisfiable() and EmptyObjectRangeNotSatisfiableException marker class.PresignedUrlMultipartDownloaderSubscriber: Wraps 416 on partIndex == 0 with marker exception instead of calling handleError.ParallelPresignedUrlMultipartDownloaderSubscriber: Wraps 416 in sendFirstRequest with marker exception. Removed forwardExceptionTo from sendFirstRequest to prevent race with the wrapping logic.Testing
PresignedUrlMultipartDownloaderSubscriberWiremockTest: Added tests for 416 fallback on first request, error propagation on subsequent request, and user-specified range on empty object.ParallelPresignedUrlMultipartDownloaderSubscriberTest: Added tests for 416 fallback on first request and error propagation on subsequent request for the parallel (toFile) path.AsyncPresignedUrlExtensionTestSuite: Added integration tests for zero-byte object download (toBytes and toFile) and user-specified range on empty object. Runs for both multipart and non-multipart clients.Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License