From 13c5881f3ec697f53ec44449c66df8f39323d513 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Thu, 22 Dec 2016 18:45:44 +0100 Subject: [PATCH] UnicastZenPing's PingingRound should prevent opening connections after being closed This may cause them to leak. Provisioning for it was made in #22277 but sadly a crucial ensureOpen call was forgotten --- .../java/org/elasticsearch/discovery/zen/UnicastZenPing.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 8018c47b4e1..4e2ed19f422 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 class UnicastZenPing extends AbstractComponent implements ZenPing { 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;