diff --git a/core/src/main/java/org/elasticsearch/transport/TcpTransport.java b/core/src/main/java/org/elasticsearch/transport/TcpTransport.java index 11afec1bf1e..ba355e41477 100644 --- a/core/src/main/java/org/elasticsearch/transport/TcpTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/TcpTransport.java @@ -411,8 +411,11 @@ public abstract class TcpTransport extends AbstractLifecycleComponent i @Override public synchronized void close() throws IOException { if (closed.compareAndSet(false, true)) { - closeChannels(Arrays.stream(channels).filter(Objects::nonNull).collect(Collectors.toList())); - onClose.accept(this); + try { + closeChannels(Arrays.stream(channels).filter(Objects::nonNull).collect(Collectors.toList())); + } finally { + onClose.accept(this); + } } }