Skip to content

Commit ed31d2c

Browse files
author
Mate Szalay-Beko
committed
ZOOKEEPER-3188: better shutdown for executors (following PR comments)
1 parent 8713a5b commit ed31d2c

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.concurrent.CountDownLatch;
4848
import java.util.concurrent.ExecutorService;
4949
import java.util.concurrent.Executors;
50+
import java.util.concurrent.TimeUnit;
5051
import java.util.concurrent.atomic.AtomicBoolean;
5152
import java.util.concurrent.atomic.AtomicLong;
5253
import java.util.stream.Collectors;
@@ -449,10 +450,17 @@ public void run() {
449450
try {
450451
latch.await();
451452
} catch (InterruptedException ie) {
452-
LOG.error("Interrupted while sleeping. Ignoring exception", ie);
453+
LOG.error("Interrupted while sleeping in LearnerCnxAcceptor.", ie);
453454
} finally {
454455
closeSockets();
455-
executor.shutdownNow();
456+
executor.shutdown();
457+
try {
458+
if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
459+
LOG.error("not all the LearnerCnxAcceptorHandler terminated properly");
460+
}
461+
} catch (InterruptedException ie) {
462+
LOG.error("Interrupted while terminating LearnerCnxAcceptor.", ie);
463+
}
456464
}
457465
}
458466
}

zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Learner.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.concurrent.CountDownLatch;
3838
import java.util.concurrent.ExecutorService;
3939
import java.util.concurrent.Executors;
40+
import java.util.concurrent.TimeUnit;
4041
import java.util.concurrent.atomic.AtomicReference;
4142
import javax.net.ssl.SSLSocket;
4243
import org.apache.jute.BinaryInputArchive;
@@ -272,7 +273,14 @@ protected void connectToLeader(MultipleAddresses addr, String hostname) throws I
272273
} catch (InterruptedException e) {
273274
LOG.warn("Interrupted while trying to connect to Leader", e);
274275
} finally {
275-
executor.shutdownNow();
276+
executor.shutdown();
277+
try {
278+
if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
279+
LOG.error("not all the LeaderConnector terminated properly");
280+
}
281+
} catch (InterruptedException ie) {
282+
LOG.error("Interrupted while terminating LeaderConnector executor.", ie);
283+
}
276284
}
277285

278286
if (socket.get() == null) {

0 commit comments

Comments
 (0)