From 30f7714b0c94aa5dbe2d4d0b6fa466fcfc95b7ad Mon Sep 17 00:00:00 2001 From: Jim Halfpenny Date: Thu, 19 Nov 2026 12:54:07 +0000 Subject: [PATCH] NIFI-16611 Add connect timeout to load balancing client sockets - Connect load balancing client sockets with a fixed 5 second timeout instead of blocking for the OS TCP connect timeout against unreachable peers. --- .../client/async/nio/NioAsyncLoadBalanceClient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/client/async/nio/NioAsyncLoadBalanceClient.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/client/async/nio/NioAsyncLoadBalanceClient.java index e7b8834a30ff..c122138b0c17 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/client/async/nio/NioAsyncLoadBalanceClient.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/client/async/nio/NioAsyncLoadBalanceClient.java @@ -60,6 +60,7 @@ public class NioAsyncLoadBalanceClient implements AsyncLoadBalanceClient { private static final Logger logger = LoggerFactory.getLogger(NioAsyncLoadBalanceClient.class); private static final long PENALIZATION_MILLIS = TimeUnit.SECONDS.toMillis(1L); + private static final int CONNECT_TIMEOUT_MILLISECONDS = (int) TimeUnit.SECONDS.toMillis(5L); private final NodeIdentifier nodeIdentifier; private final int timeoutMillis; @@ -486,7 +487,9 @@ private SocketChannel createChannel() throws IOException { final Socket socket = socketChannel.socket(); socket.setSoTimeout(timeoutMillis); - socket.connect(new InetSocketAddress(nodeIdentifier.getLoadBalanceAddress(), nodeIdentifier.getLoadBalancePort())); + // Bound the connect: without a timeout, connecting to a peer that silently drops packets (e.g. the old address of a + // restarted node) blocks for the OS TCP connect timeout, stalling every other Client served by the same task thread + socket.connect(new InetSocketAddress(nodeIdentifier.getLoadBalanceAddress(), nodeIdentifier.getLoadBalancePort()), CONNECT_TIMEOUT_MILLISECONDS); socket.setSoTimeout(timeoutMillis); return socketChannel;