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/JoinTask.java
public record JoinTask(List<NodeJoinTask> nodeJoinTasks, boolean isBecomingMaster) implements ClusterStateTaskListener {
    public static JoinTask singleNode(DiscoveryNode node, String reason, ActionListener<Void> listener) {
        return new JoinTask(List.of(new NodeJoinTask(node, reason, listener)), false);
    }
    public static JoinTask completingElection(Stream<NodeJoinTask> nodeJoinTaskStream) {
        return new JoinTask(nodeJoinTaskStream.toList(), true);
    }
    public JoinTask(List<NodeJoinTask> nodeJoinTasks, boolean isBecomingMaster) {
        this.nodeJoinTasks = Collections.unmodifiableList(nodeJoinTasks);
        this.isBecomingMaster = isBecomingMaster;
    }
    public int nodeCount() {
        return nodeJoinTasks.size();
    }
    @Override
    public void onFailure(Exception e) {
        for (NodeJoinTask nodeJoinTask : nodeJoinTasks) {
            nodeJoinTask.listener.onFailure(e);
        }
    }
    @Override
    public void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
        assert false : "not called";
    }
    @Override
    public String toString() {
        final StringBuilder stringBuilder = new StringBuilder();
        if (isBecomingMaster) {
            stringBuilder.append("_FINISH_ELECTION_");
        }