allthingssecurity opened a new pull request, #29373:
URL: https://github.com/apache/camel/pull/29373

   # Description
   
   [CAMEL-26643](https://issues.apache.org/jira/browse/CAMEL-26643)
   
   `SjmsConsumer` keeps one listener container for every run of the consumer. 
With `asyncStopListener=true`, `doStop` submits a task that stops and shuts 
down that container. If the same consumer was started again before the task ran 
(route policies that stop and start the consumer, such as `MasterRoutePolicy` 
or `HazelcastRoutePolicy`, or the stop/start operations of the managed consumer 
in JMX), the start found the container still started, and the task then shut it 
down: the consumer was Started and received nothing, with no error logged. A 
start between the `stop()` and the `shutdown()` of a running task ended the 
same way. With `asyncStartListener=true`, a start task that ran after the 
consumer was stopped started the container of a stopped consumer, which then 
kept receiving.
   
   This is the camel-sjms side of CAMEL-26536 (camel-jms). The JMS fix detaches 
the container, as `JmsConsumer` creates a new one per start. That is not 
possible here, as the container is created once with the consumer.
   
   Change (`SjmsConsumer`):
   - a lock of its own (`listenerContainerLock`) serializes the start and the 
stop of the listener container by the asynchronous tasks and by a synchronous 
`doStart`;
   - the stop task stops and shuts down the container only if the consumer is 
still stopped;
   - the start task starts it only if the consumer still runs, and stops it 
again if the consumer was stopped while it was starting;
   - the stop, shutdown and suspend of the consumer, and so a route stop, do 
not wait for the stop task, so `asyncStopListener` keeps its purpose. A 
synchronous start waits for a stop task that is stopping the container.
   
   Tests: `SjmsAsyncStartStopListenerRestartTest` (embedded Artemis). The tasks 
are held and run in a chosen order, or on a thread of their own with the 
container held between its stop and its shutdown:
   - start while the stop task is pending, in both orders of the stop and start 
tasks, and while the stop task runs;
   - stop while the start task is pending, and while it is starting the 
container;
   - a route stop does not wait for a running stop task;
   - a control with the tasks run in order.
   
   Results:
   - On main 5 of the 8 fail: the three restart cases receive nothing, and in 
the two stop cases the container keeps running. The other three pass on main by 
design: the stop-first order (the start task starts the shut-down container 
again), the route-stop test (it guards that a route stop does not wait for the 
stop task) and the in-order control.
   - With the fix 8/8, and 20 runs each (160/160).
   - camel-sjms module and camel-sjms2 module (which uses the same consumer, so 
it is fixed too): 0 failures.
   
   Backport: 4.18.x and 4.14.x have the same asynchronous stop and start tasks, 
but not CAMEL-25312 (no `getListenerContainer()`, no lock in 
`startListenerContainer`), so a backport is not a straight cherry-pick and 
needs its own small adaptation and review. Main only in this PR.
   
   # 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-26643](https://issues.apache.org/jira/browse/CAMEL-26643).
   
   # 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 core modules with camel-sjms and camel-sjms2, ran the 
formatter and import-sort plugins and the module tests; no 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]

Reply via email to