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 8018c47b4e113..4e2ed19f4224c 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java @@ -385,12 +385,14 @@ public Connection getOrConnect(DiscoveryNode node) throws IOException { try (Releasable ignore = connectionLock.acquire(node.getAddress())) { result = tempConnections.get(node.getAddress()); if (result == null) { + ensureOpen(); boolean success = false; result = transportService.openConnection(node, connectionProfile); try { transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis()); synchronized (this) { - // acquire lock to prevent concurrent closing + // acquire lock and check if closed, to prevent leaving an open connection after closing + ensureOpen(); Connection existing = tempConnections.put(node.getAddress(), result); assert existing == null; success = true;