From 7dec783b287ab554cc781622b4d6127e553fd2ae Mon Sep 17 00:00:00 2001 From: markrmiller Date: Sun, 11 Dec 2016 22:02:48 -0500 Subject: [PATCH] SOLR-9846: OverseerAutoReplicaFailoverThread can take too long to stop and leak out of unit tests. --- solr/CHANGES.txt | 2 ++ .../solr/cloud/OverseerAutoReplicaFailoverThread.java | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 946a04e6936..5f0357b3608 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -288,6 +288,8 @@ Other Changes response (instead of a SolrException) and includes the remote error message as part of the exception message (Tomás Fernández Löbbe) +* SOLR-9846: OverseerAutoReplicaFailoverThread can take too long to stop and leak out of unit tests. (Mark Miller) + ================== 6.3.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java b/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java index 83679a549c7..10b4bf3fb0e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java @@ -89,6 +89,8 @@ public class OverseerAutoReplicaFailoverThread implements Runnable, Closeable { private final int workLoopDelay; private final int waitAfterExpiration; + + private volatile Thread thread; public OverseerAutoReplicaFailoverThread(CloudConfig config, ZkStateReader zkStateReader, UpdateShardHandler updateShardHandler) { @@ -118,7 +120,7 @@ public class OverseerAutoReplicaFailoverThread implements Runnable, Closeable { @Override public void run() { - + this.thread = Thread.currentThread(); while (!this.isClosed) { // work loop log.debug("do " + this.getClass().getSimpleName() + " work loop"); @@ -136,7 +138,6 @@ public class OverseerAutoReplicaFailoverThread implements Runnable, Closeable { try { Thread.sleep(workLoopDelay); } catch (InterruptedException e) { - Thread.currentThread().interrupt(); return; } } @@ -480,6 +481,10 @@ public class OverseerAutoReplicaFailoverThread implements Runnable, Closeable { @Override public void close() { isClosed = true; + Thread lThread = thread; + if (lThread != null) { + lThread.interrupt(); + } } public boolean isClosed() {