diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java index e5c6c41fdfa..7e590d1c06c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java @@ -36,6 +36,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.TransportService; +import java.util.Iterator; import java.util.List; import java.util.Queue; import java.util.concurrent.CopyOnWriteArrayList; @@ -107,9 +108,11 @@ public class InternalClusterService extends AbstractLifecycleComponent onGoingTimeout : onGoingTimeouts) { - if (onGoingTimeout.v2().listener == listener) { - onGoingTimeout.v1().cancel(); + for (Iterator> it = onGoingTimeouts.iterator(); it.hasNext();) { + Tuple tuple = it.next(); + if (tuple.v2().listener.equals(listener)) { + tuple.v1().cancel(); + it.remove(); } } }