Skip to content

Commit 819bdfa

Browse files
authored
NIFI-16611 Add connect timeout of 5 seconds to Load Balancing Client Sockets (#11948)
Signed-off-by: David Handermann <exceptionfactory@apache.org>
1 parent 6df6779 commit 819bdfa

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/client/async/nio

‎nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/client/async/nio/NioAsyncLoadBalanceClient.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
public class NioAsyncLoadBalanceClient implements AsyncLoadBalanceClient {
6161
private static final Logger logger = LoggerFactory.getLogger(NioAsyncLoadBalanceClient.class);
6262
private static final long PENALIZATION_MILLIS = TimeUnit.SECONDS.toMillis(1L);
63+
private static final int CONNECT_TIMEOUT_MILLISECONDS = (int) TimeUnit.SECONDS.toMillis(5L);
6364

6465
private final NodeIdentifier nodeIdentifier;
6566
private final int timeoutMillis;
@@ -486,7 +487,9 @@ private SocketChannel createChannel() throws IOException {
486487
final Socket socket = socketChannel.socket();
487488
socket.setSoTimeout(timeoutMillis);
488489

489-
socket.connect(new InetSocketAddress(nodeIdentifier.getLoadBalanceAddress(), nodeIdentifier.getLoadBalancePort()));
490+
// Bound the connect: without a timeout, connecting to a peer that silently drops packets (e.g. the old address of a
491+
// restarted node) blocks for the OS TCP connect timeout, stalling every other Client served by the same task thread
492+
socket.connect(new InetSocketAddress(nodeIdentifier.getLoadBalanceAddress(), nodeIdentifier.getLoadBalancePort()), CONNECT_TIMEOUT_MILLISECONDS);
490493
socket.setSoTimeout(timeoutMillis);
491494

492495
return socketChannel;

0 commit comments

Comments
 (0)