diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java b/core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java index d0a9a212bdd..06269706e0d 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java @@ -575,7 +575,8 @@ public class UnicastZenPing extends AbstractComponent implements ZenPing { @Override public void handleException(TransportException exp) { - if (exp instanceof ConnectTransportException || exp.getCause() instanceof ConnectTransportException) { + if (exp instanceof ConnectTransportException || exp.getCause() instanceof ConnectTransportException || + exp.getCause() instanceof AlreadyClosedException) { // ok, not connected... logger.trace((Supplier) () -> new ParameterizedMessage("failed to connect to {}", node), exp); } else if (closed == false) { @@ -608,6 +609,9 @@ public class UnicastZenPing extends AbstractComponent implements ZenPing { @Override public void messageReceived(UnicastPingRequest request, TransportChannel channel) throws Exception { + if (closed) { + throw new AlreadyClosedException("node is shutting down"); + } if (request.pingResponse.clusterName().equals(clusterName)) { channel.sendResponse(handlePingRequest(request)); } else { diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java index 3c7a49a1766..853294de186 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java @@ -258,6 +258,16 @@ public class UnicastZenPingTests extends ESTestCase { assertPingCount(handleD, handleA, 0); assertPingCount(handleD, handleB, 0); assertPingCount(handleD, handleC, 3); + + zenPingC.close(); + handleD.counters.clear(); + logger.info("ping from UZP_D after closing UZP_C"); + pingResponses = zenPingD.pingAndWait().toList(); + // check that node does not respond to pings anymore after the ping service has been closed + assertThat(pingResponses.size(), equalTo(0)); + assertPingCount(handleD, handleA, 0); + assertPingCount(handleD, handleB, 0); + assertPingCount(handleD, handleC, 3); } public void testUnknownHostNotCached() throws ExecutionException, InterruptedException {