{"record":{"id":"97dda766a4aad07f","repo":"apache/druid","slug":"i-m-being-asked-to-become-leader-but-i-am-already","errorCode":null,"errorMessage":"I'm being asked to become leader. But I am already the leader. Ignored event.","messagePattern":"I'm being asked to become leader\\. But I am already the leader\\. Ignored event\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/src/main/java/org/apache/druid/curator/discovery/CuratorDruidLeaderSelector.java","lineNumber":98,"sourceCode":"\n  private LeaderLatch createNewLeaderLatchWithListener()\n  {\n    final LeaderLatch newLeaderLatch = createNewLeaderLatch();\n\n    newLeaderLatch.addListener(\n        new LeaderLatchListener()\n        {\n          @Override\n          public void isLeader()\n          {\n            try {\n              if (newLeaderLatch.getState().equals(LeaderLatch.State.CLOSED)) {\n                log.warn(\"I'm being asked to become leader, but the latch is CLOSED. Ignored event.\");\n                return;\n              }\n\n              if (leader) {\n                log.warn(\"I'm being asked to become leader. But I am already the leader. Ignored event.\");\n                return;\n              }\n\n              leader = true;\n              term.incrementAndGet();\n              listener.becomeLeader();\n            }\n            catch (Exception ex) {\n              log.makeAlert(ex, \"listener becomeLeader() failed. Unable to become leader\").emit();\n              notLeader();\n            }\n          }\n\n          @Override\n          public void notLeader()\n          {\n            try {\n              if (!leader) {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/curator/discovery/CuratorDruidLeaderSelector.java#L80-L116","documentation":"CuratorDruidLeaderSelector's isLeader() listener callback fired while the local `leader` flag was already true, meaning Curator reported a leadership grant for an existing leader. The event is ignored with a warning to keep the term counter and leadership state consistent.","triggerScenarios":"Curator's LeaderLatch re-delivers the isLeader callback — typically when the latch is recreated after a session event while the node still holds leadership, or duplicate listener registrations on the same executor.","commonSituations":"ZK session reconnection where leadership was retained, latch stop-and-recreate races, or code paths that register the listener twice.","solutions":["Generally harmless: the node is correctly still the leader and the duplicate event is dropped.","If leadership appears stuck, verify the listener.becomeLeader() side effects ran for the current term (check term counter in logs).","Investigate ZK session instability that triggers spurious re-grants.","Avoid registering multiple listeners on the same CuratorDruidLeaderSelector instance."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// make becomeLeader idempotent so duplicate grants are harmless\n@Override\npublic void becomeLeader() {\n  if (leading.compareAndSet(false, true)) {\n    doLeaderWork();\n  }\n}","preventionTips":["Register only one listener per leader selector.","Make becomeLeader side effects idempotent (guarded by a flag/lock).","Monitor ZK session churn that triggers duplicate grants."],"tags":["zookeeper","curator","leader-election","duplicate-event"],"backgroundTag":"invalid-state-transition","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}