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
}
    
    public static void ensureNodesCompatibility(final Version joiningNodeVersion, DiscoveryNodes currentNodes) {
        final Version minNodeVersion = currentNodes.getMinNodeVersion();
        final Version maxNodeVersion = currentNodes.getMaxNodeVersion();
        ensureNodesCompatibility(joiningNodeVersion, minNodeVersion, maxNodeVersion);
    }
    
    public static void ensureNodesCompatibility(Version joiningNodeVersion, Version minClusterNodeVersion, Version maxClusterNodeVersion) {
        assert minClusterNodeVersion.onOrBefore(maxClusterNodeVersion) : minClusterNodeVersion + " > " + maxClusterNodeVersion;
        if (joiningNodeVersion.isCompatible(maxClusterNodeVersion) == false) {
            throw new IllegalStateException(
                "node version ["
                    + joiningNodeVersion
                    + "] is not supported. "
                    + "The cluster contains nodes with version ["
                    + maxClusterNodeVersion
                    + "], which is incompatible."
            );
        }
        if (joiningNodeVersion.isCompatible(minClusterNodeVersion) == false) {
            throw new IllegalStateException(
                "node version ["
                    + joiningNodeVersion
                    + "] is not supported."
                    + "The cluster contains nodes with version ["
                    + minClusterNodeVersion
                    + "], which is incompatible."
            );
        }