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 b97a7a43147..bb28f8744ed 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java @@ -982,10 +982,11 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery 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; }