allthingssecurity opened a new pull request, #30461: URL: https://github.com/apache/camel/pull/30461
# Description [CAMEL-27213](https://issues.apache.org/jira/browse/CAMEL-27213) When the SEDA producer waits for the reply (an `InOut` exchange, such as an HTTP request routed to seda, or `waitForTaskToComplete=Always`), it adds a copy of the exchange to the queue with an on completion that copies the result back and releases the producer, then waits. `addToQueue` can discard that copy: `discardIfNoConsumers=true` with no consumer, or `discardWhenFull=true` with a full queue. Nothing then runs the on completion of the copy, so the producer waits for a reply that never comes: until the `timeout` (30 seconds by default), and then fails with `ExchangeTimedOutException`, or for ever when `timeout` is 0 or less. A discarded `InOnly` exchange continues at once (CAMEL-25123 hands its on completions back). With `discardWhenFull` used for load shedding in front of a request-reply route, each shed request holds its calling thread (such as an HTTP worker thread) for the whole timeout instead of being shed. Fix: when `addToQueue` discards the copy that the producer waits for (it is called with `copy=false` only on that path), it sets a `RejectedExecutionException` on the copy ("Exchange discarded as the SEDA queue has no consumers", or "... is full") and runs its on completions, as `SedaEndpoint.purgeQueue` does for the exchanges it discards ("Exchange discarded as the SEDA queue was purged", CAMEL-24950). The on completion of the wait path copies the result back, so the caller fails at once with that exception instead of waiting for the timeout. Behind an HTTP route a shed request therefore gets an error, not a 200 with its own request body. A discarded `InOnly` message is still dropped without an error (not changed). A copy that fails to be added (queue full without `discardWhenFull`, interrupted) still fails as before, and `StubProducer`, which overrides `addToQueue`, is not changed. Upgrade guide: a short 4.24 entry, as such a request now fails with `RejectedExecutionException` a t once instead of `ExchangeTimedOutException` after the timeout. Model: a small TLA+ model (`SedaInOutDiscard.tla`: the wait path with the latch, a consumer that is absent or busy, a queue of one) checks "the producer gets an answer" and "a discarded request is not answered with the timeout". On main the first is violated with no timeout (the producer waits for ever) and the second with a timeout (3 states); with the change both hold (15 and 17 distinct states), and a queued request with a slow consumer still times out as before. Tests: `SedaInOutDiscardTest` (camel-core): a request to `seda:none?discardIfNoConsumers=true&timeout=20000` without a consumer, and a request to a full queue with `discardWhenFull=true`, must fail within 5 seconds (the endpoint timeout is 20 seconds) with a `RejectedExecutionException` and the message of the discard reason; the queued messages are processed, and an `InOnly` message to the endpoint without a consumer is still dropped without an error. On main both tests fail (no answer within 5 seconds); with the change they pass (the class runs in well under a second), and the seda tests of camel-core and the camel-stub tests pass (158 + 4 run, 0 failures). The new class 10 times in one JVM: 20 run, 0 failures. # 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-27213](https://issues.apache.org/jira/browse/CAMEL-27213). # 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 the touched modules with the formatter and import-sort plugins; no option or generated file changes. 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]
