allthingssecurity opened a new pull request, #30911: URL: https://github.com/apache/camel/pull/30911
# Description [CAMEL-27588](https://issues.apache.org/jira/browse/CAMEL-27588) When the connection of the temporary reply queue's listener container fails, the exception listener calls `scheduleRefresh` of the resolver in `TemporaryQueueReplyManager`. It bumped the refresh generation and then set `replyTo` to null, without the resolver's lock. A consumer of the container recovers from the same failure on its own thread: it sees the pending refresh, takes the new generation, creates a new temporary queue and publishes it (`setReplyTo`, then the published generation). If that resolve ran between the two statements of `scheduleRefresh`, the late `replyTo = null` overwrote the queue that had just been published. No refresh was pending any more, so the recovery task was not started, and the resolver kept returning its cached queue without publishing it again. Every InOut request then waited the whole `getReplyTo` budget (20 seconds by default) and failed with "Failed to resolve replyTo destination", until the next connection failure. The container keeps running and reports nothing. The fix swaps the two statements: `scheduleRefresh` clears `replyTo` first and then bumps the generation. A consumer can only publish the new generation after it has read the bumped value, so its `setReplyTo` comes after the null write and wins. Both fields are volatile. I did not take the resolver's lock in `scheduleRefresh`. The lock is held while a consumer creates or deletes a temporary queue on the broker, so the exception listener thread would then wait for that broker call, possibly on a connection that is failing; CAMEL-20769 removed a lock from this path for a similar reason. The swap keeps the exception listener lock-free. What it does not change: a consumer that already passed its generation check before the refresh can still publish its (older) queue while the refresh is pending, as it can today; the refresh stays pending, so the recovery replaces that queue. camel-sjms is not affected: its `scheduleRefresh` only sets a flag and does not clear `replyTo`. Model: found with a TLA+ model of the refresh generations, the consumers' resolve, the recovery task and the stop (invariant: when no refresh is pending, `replyTo` is the resolver's queue; liveness: the reply destination becomes usable again after the failures stop). On main the invariant fails; with the swap all properties hold with up to 3 consumers and 3 connection failures, with and without a stop. Test: `shouldKeepReplyToWhenConsumerResolvesTheNewGenerationDuringTheRefresh` in `TemporaryQueueReplyManagerRefreshTest` (embedded Artemis, as the other tests of the class). It creates the resolver with a Mockito spy as its generation counter, through a new package-private constructor (the public one passes a new `AtomicLong`, so the main code behaves as before and the test needs no reflection on the final field). The spy's `incrementAndGet` pauses the exception listener thread right after it took the new generation; meanwhile the test resolves the destination as a consumer would, then lets the refresh finish. It checks that no refresh is pending and `replyTo` is still the new queue. On main it fails (`replyTo` is null); with the fix it passes, also 10 times in a row, and the camel-jms unit tests pass. # 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-27588](https://issues.apache.org/jira/browse/CAMEL-27588). # 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 commits carry 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]
