apache/pulsar · error · IllegalStateException

Zookeeper session expired, give up to become auditor.

Error message

Zookeeper session expired, give up to become auditor.

What it means

tryToBecomeAuditor() waits in a loop to acquire the Pulsar auditor leader role. If the ZooKeeper session expires while the thread is waiting, the coordinator sets sessionExpired=true and the method throws IllegalStateException to signal that leadership acquisition has been abandoned and must be restarted with a fresh session.

Source

Thrown at pulsar-metadata/src/main/java/org/apache/pulsar/metadata/bookkeeper/PulsarLedgerAuditorManager.java:85

            notifyAll();
        }
    }

    @Override
    public void tryToBecomeAuditor(String bookieId, Consumer<AuditorEvent> listener) {
        this.bookieId = bookieId;

        LeaderElectionState les = leaderElection.elect(bookieId).join();

        synchronized (this) {
            leaderElectionState = les;
        }

        while (true) {
            try {
                synchronized (this) {
                    if (sessionExpired) {
                        throw new IllegalStateException("Zookeeper session expired, give up to become auditor.");
                    }
                    if (leaderElectionState == LeaderElectionState.Leading) {
                        return;
                    } else {
                        wait();
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public BookieId getCurrentAuditor() {
        return leaderElection.getLeaderValue()
                .join()
                .map(BookieId::parse)

View on GitHub (pinned to 820761864e)

Solutions

  1. Verify ZooKeeper session stability: increase sessionTimeoutMs if GC pauses or network hiccups exceed it.
  2. Restart the auditor-election process after the broker re-establishes its ZooKeeper session (the coordinator typically re-runs tryToBecomeAuditor).
  3. Check broker logs for SessionExpired/Disconnect events to correlate with GC pauses or network issues.
  4. Ensure the broker's ZooKeeper client reconnect logic (session watcher) is healthy before re-attempting leadership.

Example fix

// before
coordinator.tryToBecomeAuditor(); // throws IllegalStateException on session expiry
// after
try {
    coordinator.tryToBecomeAuditor();
} catch (IllegalStateException e) {
    LOG.warn("Auditor election aborted due to ZooKeeper session expiry; will retry after reconnect", e);
    // wait for session re-establishment, then re-attempt
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Check session liveness before attempting election
if (zkClient.getSessionId() == 0 || !zkClient.getState().isAlive()) {
    throw new IllegalStateException("ZooKeeper session not alive; postpone auditor election");
}

Try / catch

try {
    coordinator.tryToBecomeAuditor();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("session expired")) {
        // wait for zk reconnect, then re-run election
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: A thread calls tryToBecomeAuditor() and blocks in wait(); the ZooKeeper session is then expired (session loss, network partition, long GC pause exceeding session timeout), triggering the IllegalStateException on wake-up.

Common situations: Broker losing ZooKeeper connectivity during network flaps; ZooKeeper session timeout too short for JVM GC pauses; broker failover storms where many brokers contend for auditor and sessions lapse.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/9ad25ec60f0a9b0a. Report an issue: GitHub.