diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java b/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java index 8758ac4eb95df..f52726403a39c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java @@ -952,10 +952,11 @@ private ClusterState clusterStateWithNoMasterBlock(ClusterState clusterState) { public void publish(ClusterChangedEvent clusterChangedEvent, ActionListener publishListener, AckListener ackListener) { try { synchronized (mutex) { - if (mode != Mode.LEADER) { - logger.debug(() -> new ParameterizedMessage("[{}] failed publication as not currently leading", - clusterChangedEvent.source())); - publishListener.onFailure(new FailedToCommitClusterStateException("node stepped down as leader during publication")); + if (mode != Mode.LEADER || getCurrentTerm() != clusterChangedEvent.state().term()) { + logger.debug(() -> new ParameterizedMessage("[{}] failed publication as node is no longer master for term {}", + clusterChangedEvent.source(), clusterChangedEvent.state().term())); + publishListener.onFailure(new FailedToCommitClusterStateException("node is no longer master for term " + + clusterChangedEvent.state().term() + " while handling publication")); return; }