allthingssecurity opened a new pull request, #29671: URL: https://github.com/apache/camel/pull/29671
# Description [CAMEL-26870](https://issues.apache.org/jira/browse/CAMEL-26870) Each start of a `MasterConsumer` creates a `ZookeeperGroupListenerSupport`, which registers itself as a connection state listener on the `CuratorFramework` it uses: the curator of the component (`ZookeeperGroupSupport.setCurator`) or the `curator` bean of the registry (looked up in its `doStart`), which the consumers share. Its `doStop` closed the group but never removed the listener, so the shared client kept one listener for every start of every consumer (a route restart, a route reload), each holding its consumer, endpoint and closed group for as long as the client lives. The listener only logs the connection state at DEBUG, so this is a leak of memory (and of DEBUG lines), not a change of mastership. Named in the review of #29583 (CAMEL-26802), which fixes the same gap for `MasterRoutePolicy` inside the policy. Change, in `ZookeeperGroupSupport` (the base of the group listeners of the consumer and the route policy, and the component's own): - it remembers the client it registered on, and removes itself from it when it stops (in a `finally`, also when closing the group fails); - it registers again when it is started again after a stop, and setting another client moves the registration to it. This does not touch the files of #29583. With both merged, the removal `MasterRoutePolicy` does itself becomes redundant (the second `removeListener` does nothing), and the client is the one the listener actually registered on, which also answers the review point on #29583 about picking the client. Tests, in `MasterConsumerLeadershipTest` (fake group, no ZooKeeper): `testStoppedConsumerLeavesNoListenerOnTheSharedCurator` binds a `curator` bean (a proxy of `CuratorFramework` with Curator's `StandardListenerManager` as its connection state listenable) and stops and starts the route three times: the number of listeners (the component and the consumer) must go back after each stop, and to 0 when the CamelContext stops. Without the change it fails at the first stop (2 listeners instead of 1). With it the camel-zookeeper-master unit tests pass (24, 0 failures), and `MasterConsumerLeadershipTest` with `MasterRoutePolicyLeadershipTest` pass 220/220 over 20 runs in one JVM. The code change applies to the older lines too, the test class exists on main only. The ITs need a ZooKeeper container and were not run locally. No documentation or upgrade guide change: nothing a user configures changes. Not changed, for follow-up JIRAs I will offer (all pre-existing): the JMX getters of `MasterConsumer` throw a `NullPointerException` before the first start and read a closed group after a stop (the other half of the review point on #29583); `ZookeeperGroupSupport.call()` stores the client it creates in its `curator` field, so a support started again after a stop reuses the closed client; `call()` ignores the `zookeeper.password` system property; a `ManagedGroupFactory` from the registry is closed by the stop of each consumer. # 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-26870](https://issues.apache.org/jira/browse/CAMEL-26870). # 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 and camel-zookeeper-master with the formatter and import-sort plugins and ran its unit tests. I did not run the full root build. The ITs, which need a ZooKeeper container, were not run locally; CI runs them.) # 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]
