allthingssecurity opened a new pull request, #28196: URL: https://github.com/apache/camel/pull/28196
# Description [CAMEL-25790](https://issues.apache.org/jira/browse/CAMEL-25790) `GooglePubsubConsumer` runs one loop per concurrent consumer: the asynchronous loop starts a `Subscriber` and waits until it terminates, the synchronous loop pulls, routes the messages and pulls again. Both loops continued while `isRunAllowed() && !isSuspendingOrSuspended()`, which misses two cases: - Graceful shutdown. `deferShutdown` (CAMEL-23291) stops the subscribers and cancels the pending pulls, but the consumer stays started while the shutdown strategy waits for its pending exchanges. The loop saw a running consumer and at once started a new subscriber, or issued a new pull, so new messages kept being routed during the wait. With a steady flow of messages the shutdown waited for its full timeout (45 s by default) and was then forced, with exchanges in flight, whose messages are delivered again. - Route restart. `doStop` only calls `stopAsync`; the subscriber terminates later. When the consumer was started again before that, the old loop woke up in a started consumer and subscribed again, next to the loops of the new start. Every restart added `concurrentConsumers` subscriber loops, and the executors of the previous start stayed until `doShutdown`. This change gives each loop a generation. The consumer increments it when it starts, in `deferShutdown` and in `doStop`; a loop of an older generation ends instead of subscribing or pulling again. The checks right after a subscriber start and after a pull is issued (CAMEL-24315) use the same condition. A start after a stop also shuts down, not gracefully, the two executors of the previous start; their loops end on their own. `doShutdown` is unchanged. No message was lost before this change and no option or default changes, so there is no upgrade note. Tests: - New `GooglePubsubConsumerStopPullingTest` (3 tests, mocked `Subscriber` and `SubscriberStub` as in `GooglePubsubConsumerStopRaceTest`): no new subscriber after `deferShutdown` (asynchronous pull), no new pull after `deferShutdown` (synchronous pull), and one running subscriber after a stop and start while the first subscriber is still terminating. Each test checks with Awaitility `during` that the count stays the same for a second. - Without the change all three fail: `expected: <1> but was: <2>` (subscribers created after the consumer stopped pulling), `expected: <1> but was: <2>` (pulls issued after the consumer stopped pulling), `expected: <2> but was: <3>` (subscribers created by a start and a restart with one concurrent consumer). - With the change the camel-google-pubsub unit tests pass: 20 run, 0 failures, 10 skipped (they need credentials or the emulator). The integration tests need the Pub/Sub emulator and were not run. How it was found: mutation testing showed the stop and shutdown paths of the consumer and the asynchronous pull untested; reading the subscriber loop against the shutdown strategy (a deferred consumer stays started until its pending exchanges are done) and against the intent of CAMEL-23291, then the JUnit tests. # 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). # 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 camel-google-pubsub, 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]
