shashank created CAMEL-27457:
--------------------------------
Summary: camel-aws2-s3 - streaming upload: after a stop and start
of the same producer the next exchange is added to the completed upload and
lost, and a stop that fails on S3 leaves the timeout task running
Key: CAMEL-27457
URL: https://issues.apache.org/jira/browse/CAMEL-27457
Project: Camel
Issue Type: Bug
Components: camel-aws2
Reporter: shashank
Assignee: shashank
h3. What happens
*1. Stop and start of the same producer loses the next exchange.*
{{AWS2S3StreamUploadProducer.doStop}} uploads and completes the open upload
({{uploadAggregate}}) but keeps the field. When the same producer instance is
started again, the next exchange smaller than the batch is added to the buffer
of the completed upload and returns success. Its bytes are never stored: the
next flush calls {{uploadPart}} for the completed upload id and S3 answers
NoSuchUpload, so the next stop fails (and without {{streamingUploadTimeout}}
every later batch flush fails the same way, as {{uploadPart}} throws before the
aggregate is reset). No S3 failure is needed. The same producer instance is
started again when it is driven directly (a {{ProducerTemplate}}, user code) or
through JMX; a route restart creates a new producer.
*2. A stop that fails on S3 leaves the timeout task running.* The S3 calls in
{{doStop}} have no catch, and the shutdown of the {{streamingUploadTimeout}}
executor came after them, outside a finally. When the upload of the stop fails
(for example a 503 after the SDK's retries), {{stop()}} throws, the producer is
FAILED, and the {{S3_Streaming_Upload_Timeout_Checker}} thread keeps running:
it later uploads and completes the aggregate of the stopped producer, holds the
producer until the CamelContext shuts down, and a {{start()}} creates a second
task. Each failed stop of a route leaks one such thread.
Also, a run of the timeout task that was waiting for the lock while {{doStop}}
held it ran after {{doStop}} returned (the executor shutdown does not stop a
run that has started).
h3. How to reproduce
A mocked {{S3Client}} that refuses parts for a completed upload (as S3 does):
send message-0, stop (message-0 is stored), start, send message-1 (success),
stop: the stop fails with NoSuchUpload and message-1 is in no object.
With {{streamingUploadTimeout}}: send message-0, make the next {{uploadPart}}
fail, stop (fails): the checker thread stays alive; start again: two checker
threads.
Found with a TLA+ model of the producer, the timeout task and the producer
lifecycle (stop, start, stop that fails), then reproduced on the real producer.
h3. Fix
{{doStop}} first shuts the timeout executor down and waits for a run that has
started, so a flush that the task is running finishes before the stop uploads
the rest and no run happens after the stop (the wait is bounded by the
{{shutdownAwaitTermination}} of the {{ExecutorServiceManager}}, 10 seconds by
default; then the stop logs a WARN and goes on). Then it completes the open
uploads as before, and in a finally it sets {{uploadAggregate}} to null and
clears the timestamp windows, whether the uploads succeeded or failed (a
failure is reported by the stop). The data of an upload that fails in the stop
is not stored, and with timestamp grouping the windows after it are not tried
and are dropped too; before, only a start of the same instance or the timeout
task left running could still upload them. The multipart upload of a failed
uploadPart stays open on S3, as today. A start after the stop creates one task
and the next exchange starts a new upload.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)