fix S3 UploadPart logic when cancelling/error a request #9901
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
As reported with #9851, we would face an issue when cancelling/error an
UploadPart
request and retrying on the same PartNumber.This was due because of our ephemeral MultipartUpload object is not fully stateless, and keeps the
EphemeralS3StoredObject
in a dict to allow easier "fusion" of all underlying parts when completing (it does not have to recreate theEphemeralS3StoredObject
on top of theLockedSpooledTemporaryFile
).Code here:
localstack/localstack/services/s3/v3/storage/ephemeral.py
Lines 237 to 250 in fb182b7
However, this created an issue when the request would error/cancel, because the
EphemeralS3StoredObject
kept the reference to theS3Part
that errored (created in the provider operation which raised an Exception, withlocalstack.services.s3.v3.storage.ephemeral.EphemeralS3StoredMultipart.open
). When creating a new S3Part in a non-failing provider operation, the asynchronous calculation of theETag
due to theaws-chunked
encoding would not set theETag
to the newS3Part
but to the previously created one, hence the returnedETag
set toNone
.Changes
The simple fix is to simply remove the part entry for the underlying storage if the writing of that part fails. It could maybe be wrapped in a context manager which would clean up only if the operation fails, but this is simple and clear what it does.
I've also added a test to verify the fix, ran the external
soto
test suite and validated that it now works.