This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 3c9203bff08 NIFI-16624 Add connect timeout to secure Site-to-Site 
socket connections (#11960)
3c9203bff08 is described below

commit 3c9203bff08d6663469e16aeb43ce93e91951fb1
Author: Jim Halfpenny <[email protected]>
AuthorDate: Tue Dec 1 02:47:01 2026 +0000

    NIFI-16624 Add connect timeout to secure Site-to-Site socket connections 
(#11960)
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
    Signed-off-by: David Handermann <[email protected]>
---
 .../client/socket/EndpointConnectionPool.java      | 43 ++++++++++++++++++----
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git 
a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
 
b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
index 53b87e2177f..156b3d27f3a 100644
--- 
a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
+++ 
b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
@@ -447,8 +447,7 @@ public class EndpointConnectionPool implements 
PeerStatusProvider {
                             + " because it requires Secure Site-to-Site 
communications, but this instance is not configured for secure communications");
                 }
 
-                final Socket socket = 
sslContext.getSocketFactory().createSocket(hostname, port);
-                socket.setSoTimeout(commsTimeout);
+                final Socket socket = createSecureSocket(hostname, port);
                 commsSession = new SocketCommunicationsSession(socket);
 
                 final Optional<String> peerIdentity = 
socketPeerIdentityProvider.getPeerIdentity(socket);
@@ -459,11 +458,7 @@ public class EndpointConnectionPool implements 
PeerStatusProvider {
                     throw new IOException(String.format("Site-to-Site Peer 
[%s] Identity not found", socket.getRemoteSocketAddress()));
                 }
             } else {
-
-                final Socket socket = new Socket();
-                socket.connect(new InetSocketAddress(hostname, port), 
commsTimeout);
-                socket.setSoTimeout(commsTimeout);
-
+                final Socket socket = connectSocket(new Socket(), hostname, 
port);
                 commsSession = new SocketCommunicationsSession(socket);
             }
 
@@ -479,6 +474,40 @@ public class EndpointConnectionPool implements 
PeerStatusProvider {
         return commsSession;
     }
 
+    private Socket createSecureSocket(final String hostname, final int port) 
throws IOException {
+        // Connect a standard Socket so that the connect is bounded by the 
communications timeout instead of
+        // blocking for the OS TCP connect timeout against a peer that 
silently drops packets, then wrap the
+        // connected Socket to avoid relying on unconnected Socket support in 
alternative SSLSocketFactory implementations
+        final Socket socket = connectSocket(new Socket(), hostname, port);
+        try {
+            final Socket sslSocket = 
sslContext.getSocketFactory().createSocket(socket, hostname, port, true);
+            sslSocket.setSoTimeout(commsTimeout);
+            return sslSocket;
+        } catch (final IOException e) {
+            closeQuietly(socket, e);
+            throw e;
+        }
+    }
+
+    private Socket connectSocket(final Socket socket, final String hostname, 
final int port) throws IOException {
+        try {
+            socket.connect(new InetSocketAddress(hostname, port), 
commsTimeout);
+            socket.setSoTimeout(commsTimeout);
+        } catch (final IOException e) {
+            closeQuietly(socket, e);
+            throw e;
+        }
+        return socket;
+    }
+
+    private void closeQuietly(final Socket socket, final IOException cause) {
+        try {
+            socket.close();
+        } catch (final IOException e) {
+            cause.addSuppressed(e);
+        }
+    }
+
     private void cleanupExpiredSockets() {
         for (final BlockingQueue<EndpointConnection> connectionQueue : 
connectionQueueMap.values()) {
             final List<EndpointConnection> connections = new ArrayList<>();

Reply via email to