exceptionfactory commented on code in PR #11960:
URL: https://github.com/apache/nifi/pull/11960#discussion_r4655423594
##########
nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java:
##########
@@ -479,6 +476,17 @@ private CommunicationsSession
establishSiteToSiteConnection(final String hostnam
return commsSession;
}
+ 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) {
+ socket.close();
Review Comment:
This `socket.close()` call can throw its own `IOException`, which would lose
the initial cause, so it should be closed quietly, or `IOException` from
`close()` should be caught and wrapped
##########
nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java:
##########
@@ -447,8 +447,9 @@ private CommunicationsSession
establishSiteToSiteConnection(final String hostnam
+ " 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);
+ // Create an unconnected 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
+ final Socket socket =
connectSocket(sslContext.getSocketFactory().createSocket(), hostname, port);
Review Comment:
There is a potential behavior change with alternative `SocketFactory`
implementations such as Bouncy Castle, which prompted a recent adjustment in PR
#11959. It may be necessary to consider other adjustments to test this
behavior, but for now, I recommend using the same behavior as that PR, creating
a connected regular `Socket` and then calling
[SSLSocketFactory.createSocket()](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/javax/net/ssl/SSLSocketFactory.html#createSocket(java.net.Socket,java.lang.String,int,boolean))
to wrap the connected Socket.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]