I observed a 7.12 cluster that was struggling to complete an election, with at least one node holding over a million `elected-as-master` tasks in its pending task queue. I suspect there were two such nodes because they were just constantly winning elections and then failing because of the next election and so on...

It's currently unclear exactly how we got into this state, but it doesn't seem completely impossible if something else causes a bunch of spurious elections somehow while the master service was blocked. There were some faulty nodes involved for sure.

In any case I believe we can and should take steps to avoid processing stale `elected-as-master` tasks.
server/src/main/java/org/elasticsearch/cluster/coordination/JoinHelper.java
);
        final List<String> dataPaths = Environment.PATH_DATA_SETTING.get(settings);
        transportService.registerRequestHandler(
            JOIN_VALIDATE_ACTION_NAME,
            ThreadPool.Names.CLUSTER_COORDINATION,
            ValidateJoinRequest::new,
            (request, channel, task) -> {
                final ClusterState localState = currentStateSupplier.get();
                if (localState.metadata().clusterUUIDCommitted()
                    && localState.metadata().clusterUUID().equals(request.getState().metadata().clusterUUID()) == false) {
                    throw new CoordinationStateRejectedException(
                        "This node previously joined a cluster with UUID ["
                            + localState.metadata().clusterUUID()
                            + "] and is now trying to join a different cluster with UUID ["
                            + request.getState().metadata().clusterUUID()
                            + "]. This is forbidden and usually indicates an incorrect "
                            + "discovery or cluster bootstrapping configuration. Note that the cluster UUID persists across restarts and "
                            + "can only be changed by deleting the contents of the node's data "
                            + (dataPaths.size() == 1 ? "path " : "paths ")
                            + dataPaths
                            + " which will also remove any data held by this node."
                    );
                }
                joinValidators.forEach(action -> action.accept(transportService.getLocalNode(), request.getState()));
                channel.sendResponse(Empty.INSTANCE);
            }
        );
    }
    boolean isJoinPending() {
        return pendingOutgoingJoins.isEmpty() == false;