shashank created CAMEL-27455:
--------------------------------

             Summary: camel-aws2-s3 - streaming upload: a failed 
streamingUploadTimeout upload drops acknowledged data, and a failed exchange is 
stored twice after redelivery
                 Key: CAMEL-27455
                 URL: https://issues.apache.org/jira/browse/CAMEL-27455
             Project: Camel
          Issue Type: Bug
          Components: camel-aws2
            Reporter: shashank
            Assignee: shashank


h3. What happens

*1. A failed upload of the streamingUploadTimeout drops data that was already 
acknowledged.* With {{streamingUploadMode=true}} and 
{{streamingUploadTimeout}}, an exchange smaller than the batch is only 
buffered, and it returns success. The timeout task then uploads and completes 
the buffered data. When {{uploadPart}} or {{completeMultipartUpload}} fails 
(the SDK has given up its own retries, for example after a few 503 SlowDown 
answers), the task only logs a WARN and forgets the buffered data: without 
timestamp grouping it sets the open upload to null, with 
{{timestampGroupingEnabled}} it removes the window anyway. The exchanges whose 
data it was have already returned success, so nothing tells the route that 
their data is not stored. When {{uploadPart}} was the call that failed, the 
multipart upload is also never aborted and stays open in the bucket.

*2. A failed exchange stays in the open upload, so its redelivery stores it 
twice.* Without timestamp grouping, an exchange writes its bytes into the 
buffer of the open upload before it uploads a part. When {{uploadPart}} throws 
(the exchange reaches {{batchMessageNumber}}, {{batchSize}} or a part in 
multipart mode), the exchange fails but its bytes stay buffered. The error 
handler redelivers it and its bytes are added again, so the next upload stores 
them twice.

h3. How to reproduce

1: a mocked {{S3Client}}, {{streamingUploadTimeout}} set. Send {{message-0}} 
(it returns success), let one {{uploadPart}} answer 503, run the timeout task, 
then stop the producer: {{stop()}} succeeds, the bucket is empty and the 
multipart upload is still open. With {{timestampGroupingEnabled=true}} it is 
the same.

2: {{batchMessageNumber=2}}: send {{message-0}}, send {{message-1}} while 
{{uploadPart}} answers 503 (it fails), send {{message-1}} again (the 
redelivery). The object is {{message-0 message-1 message-1}}. In multipart mode 
a body that spans two parts, with the second part failing, is stored twice in 
the same way.

Found with a TLA+ model of the producer threads, the timeout task and the 
producer lifecycle against an S3 fake that can fail.

h3. Fix

1: when uploading the buffered data fails, the timeout task keeps it (the 
upload stays open) and the next run of the timeout, or the next exchange that 
completes the batch, uploads it again. After 3 runs that failed to upload it 
the multipart upload is aborted (a part uploaded in between by an exchange 
starts the count again). When the data is lost (given up, or completing the 
upload failed, which aborts it as before), the failure goes to the endpoint's 
exceptionHandler when one is set, and is logged at ERROR otherwise, naming the 
object, the multipart upload id and the number of exchanges. A failure, also 
one thrown by the exceptionHandler, still never stops the timeout task 
(CAMEL-24195).

2: before an exchange adds its bytes to the open upload, the producer remembers 
the buffer size, the uploaded parts and the counters. When the exchange fails 
while the upload is still open, it puts them back (and the buffered bytes of 
the earlier exchanges, when a part with them was uploaded during the exchange), 
so the redelivery stores the exchange once.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to