allthingssecurity opened a new pull request, #30820: URL: https://github.com/apache/camel/pull/30820
# Description [CAMEL-27519](https://issues.apache.org/jira/browse/CAMEL-27519) `DisruptorReference.reconfigure()` (a consumer of a `disruptor` endpoint starts, stops, is suspended or resumed) clears the reference and marks it as "being reconfigured" (`disruptor.set(null, true)`), shuts the old Disruptor down, then calls `start()`. If `start()` throws, for example when the executor of the event handlers rejects them (`RejectedExecutionException` from `executeDelayedCommands`), or a thread cannot be created, the `finally` only unlocks. The mark stays set: - every producer then waits in `getCurrentDisruptor()` forever (`parkNanos(1)` in a loop), also a producer with a `timeout`, as the timeout only starts after the exchange is published; - `DelayedExecutor` keeps the event processors it had not handed to the executor yet, and the next `start()` hands them over too: event processors of a Disruptor nobody publishes on, which take threads of the pool sized for the real ones. The route start fails and is reported, but the producers of the queue do not fail, they hang. The same applies to the other two callers of `start()`: an endpoint added again after the last one was removed, and the move of the event handlers to another CamelContext (disruptor-vm). ## The fix `start()` handles its own failure: it sets the reference to `(null, false)`, so producers fail at once with `DisruptorNotStartedException` (the exchange gets `IllegalStateException: Disruptor was not started`), as when no Disruptor is started. It also drops the event processors still queued in `DelayedExecutor`, halts the ones already handed over, logs one WARN line with the cause, and rethrows. The exchanges buffered from a queue without consumer stay buffered and are published by the next successful start, as before; the next lifecycle event (a route stopped or started again) starts the Disruptor again. In practice that happens at once: `BaseService` stops a service whose start failed, so the consumer of the route that failed to start is removed and the disruptor is reconfigured again right away, which works as soon as the executor accepts the event handlers. Not changed here: - an InOut producer without timeout whose exchange is in that buffer keeps waiting until the next successful start, the same as when it sends to a queue whose consumers are all stopped; - an executor that rejects every task (shut down by its CamelContext) is not replaced; I found no path on main that leaves the disruptor with such an executor (CAMEL-25849 moves the event handlers away from a stopping CamelContext), so this is about not hanging when a start fails, not about a known trigger; - producers that publish on the old ring buffer while it is replaced: a separate PR. Both change `DisruptorReference`, in different places, and merge without conflict. ## How it was found A TLA+ model of the reconfiguration with one injected `start()` failure: on main, every producer waits forever. Reproduced against the real code by giving the disruptor an executor that rejects its event handlers. ## Tests New `DisruptorFailedReconfigureTest` (package-private, JUnit assertions as in the module, Awaitility, no sleeps). The CamelContext gets a `ThreadPoolFactory` whose pools reject tasks while a flag is set (public API, no reflection). A second consumer route is added while they reject: the route start fails, then an InOut producer with `timeout=1000` fails with `DisruptorNotStartedException` in its cause chain (on main it waits forever; if it does not fail, the test says so instead of failing with a `NullPointerException`), and after the pool accepts again, stopping and starting the first route makes the queue work again (the message is consumed). On main the test fails in 3 runs out of 3 (the producer is still in `getCurrentDisruptor` 35 s later, or the 20 s wait for it runs out). With the fix: 20 times in one JVM, 20/20; camel-disruptor 137 tests, 0 failures. Merged with the two separate PRs that also change `DisruptorReference` (no conflict): camel-disruptor 144 tests, 0 failures. Found next to it, not changed here (a separate PR): when the thread that runs `start()` or `shutdownDisruptor()` is interrupted while it waits for an event handler to start or stop (for example the shutdown task of a CamelContext stop that timed out), the wait loop restores the interrupt flag and waits again, which throws at once: it logs "Interrupted while waiting for the startup to complete" in a busy loop forever. Main reaches it in the teardown of this test: the event handler of the next start does not start there, and the shutdown task is interrupted while it waits (it logged that line about 2 GB worth within a minute). Backport: the same code is on camel-4.22.x, camel-4.18.x and camel-4.14.x. _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]
