diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java index 095a8c5936503..80cf335a54b83 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -110,7 +110,10 @@ protected void masterOperation( ? acceptableClusterStatePredicate : acceptableClusterStatePredicate.or(clusterState -> clusterState.nodes().isLocalNodeElectedMaster() == false); - if (acceptableClusterStatePredicate.test(state) && cancellableTask.isCancelled() == false) { + if (cancellableTask.notifyIfCancelled(listener)) { + return; + } + if (acceptableClusterStatePredicate.test(state)) { ActionListener.completeWith(listener, () -> buildResponse(request, state)); } else { assert acceptableClusterStateOrFailedPredicate.test(state) == false;