{"record":{"id":"070bc8521949c685","repo":"apache/druid","slug":"i-m-being-asked-to-stop-being-leader-but-i-am-not","errorCode":null,"errorMessage":"I'm being asked to stop being leader. But I am not the leader. Ignored event.","messagePattern":"I'm being asked to stop being leader\\. But I am not 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":117,"sourceCode":"                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) {\n                log.warn(\"I'm being asked to stop being leader. But I am not the leader. Ignored event.\");\n                return;\n              }\n\n              leader = false;\n              // give others a chance to become leader.\n              stopAndCreateNewLeaderLatch();\n              listener.stopBeingLeader();\n              startLeaderLatch();\n            }\n            catch (Throwable ex) {\n              // Shutdown the service since it is now in a non-deterministic state and might never recover\n              log.makeAlert(ex, \"listener.stopBeingLeader() failed. Shutting down service.\").emit();\n              System.exit(1);\n            }\n          }\n        },\n        listenerExecutor\n    );","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/curator/discovery/CuratorDruidLeaderSelector.java#L99-L135","documentation":"CuratorDruidLeaderSelector's notLeader() listener callback fired while the local `leader` flag was false, meaning Curator reported a leadership loss for a node that does not consider itself leader. The event is ignored with a warning since there is nothing to relinquish.","triggerScenarios":"A notLeader event delivered twice, or after the leader flag was already cleared by an earlier notLeader call — e.g. latch close during stopAndCreateNewLeaderLatch() firing the listener again, or events racing during shutdown.","commonSituations":"ZK session loss causing multiple latch callbacks, rapid leader flapping, or shutdown where the latch closes and Curator emits a final notLeader notification.","solutions":["Usually benign — the node already relinquished leadership; no action needed.","If seen frequently, check ZK session stability and network partition logs.","Confirm stopLeadership lifecycle ordering: unregisterListener() should stop the executor only after the service finished handling the last notLeader event.","Check for overlapping latch instances (old latch callbacks still attached) if the warning appears after normal leader handoff."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// make notLeader handling idempotent\n@Override\npublic void stopBeingLeader() {\n  if (leading.compareAndSet(true, false)) {\n    cleanupLeaderState();\n  }\n}","preventionTips":["Ensure your LeadershipListener's stopBeingLeader tolerates being called before/without becomeLeader.","Verify unregisterListener() runs only in the service stop phase.","Watch for ZK session loss storms causing repeated callback races."],"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"}