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/JoinTaskExecutor.java
}
    /**
     * ensures that the joining node's version is equal or higher to the minClusterNodeVersion. This is needed
     * to ensure that if the master is already fully operating under the new version, it doesn't go back to mixed
     * version mode
     **/
    public static void ensureVersionBarrier(Version joiningNodeVersion, Version minClusterNodeVersion) {
        if (joiningNodeVersion.before(minClusterNodeVersion)) {
            throw new IllegalStateException(
                "node version ["
                    + joiningNodeVersion
                    + "] may not join a cluster comprising only nodes of version ["
                    + minClusterNodeVersion
                    + "] or greater"
            );
        }
    }
    public static Collection<BiConsumer<DiscoveryNode, ClusterState>> addBuiltInJoinValidators(
        Collection<BiConsumer<DiscoveryNode, ClusterState>> onJoinValidators
    ) {
        final Collection<BiConsumer<DiscoveryNode, ClusterState>> validators = new ArrayList<>();
        validators.add((node, state) -> {
            ensureNodesCompatibility(node.getVersion(), state.getNodes());
            ensureIndexCompatibility(node.getVersion(), state.getMetadata());
        });
        validators.addAll(onJoinValidators);
        return Collections.unmodifiableCollection(validators);
    }
}