docs: @Override
    public synchronized CompletableFuture<Void> leave() {
      if (leaveFuture != null) {
        return leaveFuture;
      }
  
      leaveFuture = new CompletableFuture<>();
  
      raft.getThreadContext().execute(() -> {
        // If a join attempt is still underway, cancel the join and complete the join future exceptionally.
        // The join future will be set to null once completed.
        cancelJoinTimer();
        if (joinFuture != null) {
          joinFuture.completeExceptionally(new IllegalStateException("failed to join cluster"));
        }
  
        // If there are no remote members to leave, simply transition the server to INACTIVE.
        if (getActiveMemberStates().isEmpty() && configuration.index() <= raft.getCommitIndex()) {
          log.trace("Single member cluster. Transitioning directly to inactive.");
          raft.transition(RaftServer.Role.INACTIVE);
          leaveFuture.complete(null);
        } else {
          leave(leaveFuture);
        }
      });
  
      return leaveFuture.whenComplete((result, error) -> leaveFuture = null);
    }