apache/druid · warning
I'm being asked to become leader, but the latch is CLOSED…
Error message
I'm being asked to become leader, but the latch is CLOSED. Ignored event.
What it means
CuratorDruidLeaderSelector's internal LeaderLatchListener.isLeader() was invoked by Curator while the LeaderLatch had already been closed (State.CLOSED) during a latch swap or shutdown. The callback is ignored and a warning logged, because leadership cannot be accepted on a closed latch.
Solutions
- No action needed if it appears during shutdown or latch recreation — the event is intentionally ignored.
- If it recurs during normal operation, investigate ZK session churn (session timeouts, connectivity) that forces latch recreation.
- Ensure unregisterListener()/lifecycle stop is not called before the service finishes its leader work.
- Upgrade Curator/Druid if the latch state race causes missed leadership (stale latch never replaced).
Defensive patterns
Strategy: fallback
Try / catch
// events on a closed latch are intentionally dropped; guard your leader-side effects
@Override
public void becomeLeader() {
if (!started) { return; } // ignore callbacks after service stop
doLeaderWork();
} Prevention
- Keep ZK sessions stable; tune session timeout for your network.
- Avoid stopping the leader selector while leadership grants are in flight.
- Log latch lifecycle events to correlate this warning with latch swaps.
When it happens
Trigger: A leadership-granted event delivered concurrently with stopAndCreateNewLeaderLatch() (triggered by a prior notLeader event) or with unregisterListener()/service shutdown — Curator's listener fires after the old latch was closed.
Common situations: Rapid leader flapping (frequent leadership loss/regain), ZK session instability causing latch recreation, or server shutdown while a leadership grant is still in flight.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Could not close old leader latch; continuing with new one…
- Failed to close LeaderLatch.
- I'm being asked to become leader. But I am already the…
- I'm being asked to stop being leader. But I am not the…
- can't start.
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/ef49850bccd1f156.
Report an issue: GitHub.
Appendix: source
Thrown at server/src/main/java/org/apache/druid/curator/discovery/CuratorDruidLeaderSelector.java:93
private LeaderLatch createNewLeaderLatch()
{
return new LeaderLatch(curator, latchPath, self.getServiceScheme() + "://" + self.getHostAndPortToUse());
}
private LeaderLatch createNewLeaderLatchWithListener()
{
final LeaderLatch newLeaderLatch = createNewLeaderLatch();
newLeaderLatch.addListener(
new LeaderLatchListener()
{
@Override
public void isLeader()
{
try {
if (newLeaderLatch.getState().equals(LeaderLatch.State.CLOSED)) {
log.warn("I'm being asked to become leader, but the latch is CLOSED. Ignored event.");
return;
}
if (leader) {
log.warn("I'm being asked to become leader. But I am already the leader. Ignored event.");
return;
}
leader = true;
term.incrementAndGet();
listener.becomeLeader();
}
catch (Exception ex) {
log.makeAlert(ex, "listener becomeLeader() failed. Unable to become leader").emit();
notLeader();
}
}
View on GitHub (pinned to 9b90983fd2)