allthingssecurity opened a new pull request, #30811: URL: https://github.com/apache/camel/pull/30811
# Description [CAMEL-27455](https://issues.apache.org/jira/browse/CAMEL-27455) Two failure paths of the streaming upload producer (`streamingUploadMode=true`) lose data or store it twice. **1. A failed upload of the `streamingUploadTimeout` drops data that was already acknowledged.** An exchange smaller than the batch is only buffered, and it returns success. When the timeout runs, the timeout task uploads the buffered data as a part and completes the upload. When `uploadPart` or `completeMultipartUpload` failed (after the SDK's own retries, for example on 503 SlowDown), the task logged a WARN and forgot the buffered data: without timestamp grouping it set the open upload to null, with `timestampGroupingEnabled` it removed the window anyway. The exchanges of that data had returned success, so nothing told the route. When `uploadPart` was the call that failed, the multipart upload was not aborted either and stayed 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, then uploads a part when the batch or the part is full. When `uploadPart` threw, the exchange failed but its bytes stayed buffered. The redelivery added them again, so the next upload stored them twice: with `batchMessageNumber=2`, `message-0`, a failing `message-1` and its redelivery gave the object `message-0 message-1 message-1`. The change, in `AWS2S3StreamUploadProducer`: - The timeout task keeps the data when uploading it fails: the upload stays open, and the next run of the timeout (or the next exchange, which adds to the same upload and completes it at the batch limit) uploads it again. A part uploaded again replaces the part with the same number, so a retry after a part that S3 stored but answered with an error does not duplicate it. This is bounded: after 3 runs that failed to upload the data, the task aborts the multipart upload (a part uploaded in between, by an exchange in multipart mode, starts the count again). When the data is lost this way, or because completing the upload failed (`completeUpload` aborts the upload then, as before), the failure goes to the `exceptionHandler` of the endpoint when one is set, and is logged at ERROR otherwise. The message names the object, the multipart upload id and the number of exchanges whose data is not stored (no message content). A failed run logs one WARN line (the stack trace at DEBUG). The task still catches every `Exception`, also one thrown by the `exceptionHandler` (the loss is then logged at ERROR), so a failure never stops it (CAMEL-24195). The same applies to the windows of `timestampGroupingEnabled`: a window whose upload failed is kept for the next run instead of removed. - Before an exchange adds its bytes to the open upload, the producer notes the buffer size, the uploaded parts and the counters. When the exchange fails while that upload is still open, it puts them back. In multipart mode a part with the earlier exchanges' bytes may have been uploaded during the failing exchange: the producer copies those bytes before that first upload (only then, once per exchange), puts them back in the buffer, and drops the parts of the exchange from the list, so the part numbers are uploaded again and S3 discards the parts that are not completed. The copy holds up to one part (`partSize`) in memory until the exchange ends, for an exchange that crosses a part boundary of an open upload. When completing the upload failed, the upload is aborted and nulled as before, so there is nothing to put back. Why 3 runs and not an option: a new option means a new endpoint parameter in the catalog and both DSLs for a case that should be rare (the SDK has already retried each call). The data of the open upload is bounded by the batch either way, since an exchange that fails no longer stays in it. If an option is wanted, I can add it here or in a follow-up. The endpoint's `exceptionHandler` is documented as a consumer option. I use it here because it is the handler a user can already set on an `aws2-s3` endpoint, so the loss can go to alerting; without one the producer logs at ERROR. If a producer-side use of it is not wanted, it can be a plain ERROR log. Found with a TLA+ model of the producer threads, the timeout task and the producer lifecycle against an S3 fake that can fail. Without the fixes the model breaks `NoSilentLoss` (an acknowledged message is neither stored, pending nor reported) after 54 distinct states and `NoFailedStored` (a failed exchange is also stored) after 276; the fixes are written into the model too, but that run was not done for this PR. Tests: the new `AWS2S3StreamUploadFailedFlushTest` (package-private, no sleeps). The timeout task is not scheduled: the test gives the producer a scheduler that only records the task, and runs it. The mocked `S3Client` keeps the parts of each upload by part number as S3 does (a part uploaded again replaces the one with the same number), builds the object from the parts listed by `completeMultipartUpload`, and answers 404 NoSuchUpload for a completed or aborted upload. - `timeoutUploadKeepsTheDataWhenUploadingItFails`: one failed `uploadPart` in a run, the next run stores the data; - `nextExchangeUploadsTheDataKeptByAFailedTimeoutUpload`: after a failed run, the next exchange completes the batch with both exchanges in one object; - `timeoutUploadIsAbortedAndReportedAfterThreeFailedRuns`: open after two failed runs, aborted and reported (object, upload id, 1 exchange) after the third; the next exchange starts a new upload; - `timeoutUploadWhoseCompletionFailsIsReported`: a failed `completeMultipartUpload` is reported; - `timeoutTaskKeepsRunningWhenTheExceptionHandlerFails`: an `exceptionHandler` that throws does not stop the task; the aborted upload is dropped and the next exchange is stored by the next run; - `uploadedPartStartsTheCountOfFailedTimeoutRunsAgain`: in multipart mode, two failed runs, then an exchange uploads a part with the kept data; one more failed run keeps the upload open and the next run stores everything; - `timeoutUploadOfATimestampWindowKeepsTheDataWhenUploadingItFails`: the same as the first one for a timestamp window; - `failedExchangeIsNotStoredAgainWhenItIsRedelivered`: `message-0`, a failed `message-1` and its redelivery give `message-0 message-1`; - `failedExchangeOfAMultipartUploadIsNotStoredAgainWhenItIsRedelivered`: in multipart mode an exchange that fills a part with the previous exchange's bytes and fails on its second part is stored once after its redelivery. On `main` all 9 fail: the data of the timeout tests is never stored (the upload stays open, nothing is reported), the failed `completeMultipartUpload` is not reported, and the redelivered exchange is stored twice (`message-0 message-1 message-1`, and 60 bytes instead of 30 in multipart mode). With the change all 9 pass, and the camel-aws2-s3 unit tests pass (158 run, 0 failures, 0 skipped; run offline, with the AWS SDK version of `main`, 2.57.11). The new class 20 times in one JVM: 180 run, 0 failures; with `AWS2S3StreamUploadConcurrentExchangesTest` and `AWS2S3StreamUploadMultipartTest`, 20 times: 280 run, 0 failures. Docs: a paragraph in `aws2-s3-streaming.adoc` (and its catalog copy) on what happens when the timeout upload or an exchange's upload fails. No upgrade guide entry: there is nothing for users to change; data that was dropped is now stored, or reported when it is lost. Not changed: - `doStop` and the stop/start of the same producer instance, and the timestamp grouping path of the producer threads (it takes the lock per chunk, so two exchanges of one window can interleave). Both are fixed in separate PRs on the same class, which merge cleanly with this one. - With timestamp grouping, a failing exchange still aborts the upload of its window, as before. - An exchange larger than one batch is still split over objects; when a later object of it fails, the objects completed before stay. This builds on CAMEL-26539 (one exchange at a time, on `main` for 4.24): the restore relies on the exchange holding the lock for all its writes. Older lines have the same two failure paths without that lock. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-27455](https://issues.apache.org/jira/browse/CAMEL-27455). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested the affected module, including the formatter and import-sort plugins. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
