apache/pulsar · error · RestException

Leader cannot be determined

Error message

Leader cannot be determined

What it means

getClusterLeader returns 500 with this message when the worker's MembershipManager reports no current leader (getLeader() returns null). The functions worker cluster has not elected (or has lost) a coordinator.

Source

Thrown at pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/WorkerImpl.java:108

        throwIfNotSuperUser(authParams, "get cluster");

        List<WorkerInfo> workers = worker().getMembershipManager().getCurrentMembership();
        return workers;
    }

    @Override
    public WorkerInfo getClusterLeader(AuthenticationParameters authParams) {
        if (!isWorkerServiceAvailable()) {
            throwUnavailableException();
        }

        throwIfNotSuperUser(authParams, "get cluster leader");

        MembershipManager membershipManager = worker().getMembershipManager();
        WorkerInfo leader = membershipManager.getLeader();

        if (leader == null) {
            throw new RestException(Status.INTERNAL_SERVER_ERROR, "Leader cannot be determined");
        }

        return leader;
    }

    @Override
    public Map<String, Collection<String>> getAssignments(AuthenticationParameters authParams) {
        if (!isWorkerServiceAvailable()) {
            throwUnavailableException();
        }

        throwIfNotSuperUser(authParams, "get cluster assignments");

        FunctionRuntimeManager functionRuntimeManager = worker().getFunctionRuntimeManager();
        Map<String, Map<String, Assignment>> assignments = functionRuntimeManager.getCurrentAssignments();
        Map<String, Collection<String>> ret = new HashMap<>();
        for (Map.Entry<String, Map<String, Assignment>> entry : assignments.entrySet()) {
            ret.put(entry.getKey(), entry.getValue().keySet());

View on GitHub (pinned to 820761864e)

Solutions

  1. Wait for leader election to complete and retry the request
  2. Check metadata store connectivity for all workers
  3. Inspect worker logs for election/coordination errors
  4. Verify at least one functions worker is fully started and registered in the membership manager

Example fix

// before
WorkerInfo leader = admin.worker().getClusterLeader(); // during startup -> 500
// after
await().atMost(30, SECONDS).until(() -> {
    try { admin.worker().getClusterLeader(); return true; }
    catch (PulsarAdminException e) { return false; }
});
Defensive patterns

Strategy: retry

Validate before calling

// no client-side pre-check exists; verify cluster health first
try { admin.worker().getCluster(); } // will also fail without a healthy worker cluster
catch (PulsarAdminException e) { throw new IllegalStateException("worker cluster unhealthy", e); }

Type guard

boolean leaderAvailable(PulsarAdmin admin) {
    try { admin.worker().getClusterLeader(); return true; }
    catch (PulsarAdminException e) { return false; }
}

Try / catch

Retryer<WorkerInfo> r = RetryerBuilder.<WorkerInfo>newBuilder()
    .retryIfException(e -> e instanceof PulsarAdminException
        && ((PulsarAdminException) e).getStatusCode() == 500)
    .withWaitStrategy(WaitStrategies.exponentialWait())
    .withStopStrategy(StopStrategies.stopAfterDelay(Duration.ofSeconds(30).toMillis()))
    .build();
WorkerInfo leader = r.call(() -> admin.worker().getClusterLeader());

Prevention

When it happens

Trigger: GET /worker/leader (getClusterLeader) during worker startup, a leadership election, or when all workers have lost coordination (e.g. metadata store partition).

Common situations: Fresh cluster where election has not completed; metadata store (ZooKeeper et al.) outage causing leader loss; all workers restarting simultaneously; split-brain healing period after network issues.

Related errors


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