allthingssecurity opened a new pull request, #30249: URL: https://github.com/apache/camel/pull/30249
# Description [CAMEL-27037](https://issues.apache.org/jira/browse/CAMEL-27037) Found by the DST world in #30137 (CAMEL-26974), in two cases its default set leaves out: with `-Ddst.zookeeper.stopWhileSuspended=true` 7 of 5000 seeds fail, and with `-Ddst.zookeeper.stopDuringCreate=true` 100 of the first 1189 seeds fail (the run stops at 100). Reproduced here with a plain unit test against a ZooKeeper server in the JVM, outside the DST harness. When the master consumer stops, or the route of the `MasterRoutePolicy` is removed, its `ZooKeeperGroup` is closed: it interrupts its thread and deletes its ephemeral znode (`doUpdate(null)`). The CuratorFramework is often shared and outlives the group (the client of the component, or the `curator` bean), so its session, and every ephemeral znode of that session, lives on. Two cases left the znode in the group: - the group is closed while the client is disconnected: `doUpdate(null)` deleted the znode only `if (isConnected())`, and then forgot its path. When the client reconnects to the same session (a connection loss shorter than the session timeout), the znode is still there; - the group is closed while its thread waits for the answer of a create: the interrupt ends the wait, but the server applies the create; the group never recorded the path and only logged "Ephemeral node could be created in the registry, but ZooKeeper group didn't record its id". The znode then stays in the group as long as the session lives, as a member of its own (the container id is new for each join, unless `runtime.id` is set). While it has the lowest sequence it is the master of the group, so no node runs the route, this node included after its route started again. ZooKeeper removes an ephemeral znode only when its session ends, so the client has to delete it. Curator's `DeleteBuilder.guaranteed()` is meant for this: a failed delete is recorded and Curator will "attempt to delete them in the background until successful" while the CuratorFramework is open. The znodes of a group already carry its uuid (`NodeState.uuid`), which `prunePartialState` uses to delete the duplicate of a create whose answer was lost. Change, in `ZooKeeperGroup.doUpdate(null)`: - when the client is disconnected, the znode is deleted with `delete().guaranteed().inBackground()`. The close does not wait for the connection (as before); Curator deletes the znode once the client is connected again, and if the session expired first, ZooKeeper removed it already. When connected, the foreground guaranteed delete stays as it was. - when a create did not answer and the client is connected, the group reads the children of its path and deletes those that carry its uuid. The reads come after the create in the order of the session, so they see the znode if the server applied the create. It asks the client itself whether it is connected, not only the view of the group: the close removes the listener of the group first, so the group may not have been told that the client is connected again, and the create may have been made just after the reconnect (the DST world found this case). While the client is disconnected it still only logs, as before. Not covered: the answer of a create lost with the connection, and the group closed before the reconnect; the znode then stays until the session ends, as on main. Tests, new `ZooKeeperGroupCloseTest` (a `ZooKeeperServer` in the JVM, as in `MasterRoutePolicyRouteLifecycleTest`, and a CuratorFramework with a 30 second session): - `groupClosedWhileDisconnectedDeletesItsZnodeOnceReconnected`: a group joins, the server stops, the group is closed while disconnected, the server starts again on the same data directory and the client reconnects to the same session (checked); the znode must be gone; - `groupClosedDuringACreateDeletesTheZnode`: the client applies the create and then waits for its answer until the thread is interrupted, as the ZooKeeper client does when the close interrupts it (a proxy of the CuratorFramework around the real one); the znode must be gone after the close. - `groupClosedDuringACreateBeforeItKnowsItIsConnectedAgainDeletesTheZnode`: the same, with the group told that the connection was lost and not that it is back (the client is connected). Without the change all three fail on main (the znode is still in the group 20 seconds after the reconnect, and after the close); with it all three pass, and the camel-zookeeper-master unit tests pass (43 run, 0 failures). The ITs need a ZooKeeper container and were not run locally (CI runs them). With the change merged locally into the world of #30137, and two small changes to its fake (test only; the default set still passes on main with them): `-Ddst.zookeeper.stopDuringCreate=true` passes 5000 of 5000 seeds (100 of the first 1189 fail without the change), `-Ddst.zookeeper.stopWhileSuspended=true` passes 5000 of 5000 (7 fail without it), and the default set passes 5000 of 5000 with and without it. The fake changes: it models a guaranteed delete in the background (main never makes one), and an interrupted retry sleep ends the retries of the client, as Curator's `SleepingRetry` does (without that, a create interrupted in its retry sleep was still made after the close, which a real client does not do; 12 of 5000 seeds failed on that alone). They are in #30137 now (its commit "DST world: model the background guaranteed delete"). No documentation or upgrade guide change. Backport: camel-4.18.x has the same `doUpdate`; the change applies there. # 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-27037](https://issues.apache.org/jira/browse/CAMEL-27037). # 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 camel-zookeeper-master and the core modules with the formatter and import-sort plugins and ran the camel-zookeeper-master unit tests. 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]
