gnodet-bot commented on code in PR #27613:
URL: https://github.com/apache/camel/pull/27613#discussion_r4246579566
##########
components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterView.java:
##########
@@ -83,12 +83,15 @@ protected void doStart() throws Exception {
}
fireLeadershipChangedEvent((CamelClusterMember) null);
+ // Register the listener once before attempting to connect;
registering inside
+ // the retry loop would accumulate duplicate listeners across retries.
+ raftHandle.addRoleListener(new ClusterRoleChangeListener(this));
Review Comment:
⚠️ **Listener leak on `stop`→`start` cycles:** `addRoleListener` is now
called once per `doStart`, but `doStop` never calls `removeRoleListener`. After
N restart cycles on the same `raftHandle` instance, N listeners accumulate and
N `fireLeadershipChangedEvent` calls fire per role change.
Track the listener as a field and remove it in `doStop`:
```suggestion
// Register the listener once before attempting to connect;
registering inside
// the retry loop would accumulate duplicate listeners across
retries.
roleListener = new ClusterRoleChangeListener(this);
raftHandle.addRoleListener(roleListener);
```
Then in `doStop` (before disconnecting): `if (raftHandle != null &&
roleListener != null) { raftHandle.removeRoleListener(roleListener);
roleListener = null; }`
--
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]