orb
orb copied to clipboard
Enhancement: Add Configurable Timeout to Socket Connection Methods
The ORB does not set a timeout when establishing a connection, and in some cases, such as when the opposite endpoint has set up firewall rules or is connecting to a non-existent IP address, the connection process will block for a long time at the native method:
"http-listener-1(3)" #42 daemon prio=5 os_prio=31 cpu=10.88ms elapsed=436.72s tid=0x00007f8218374800 nid=0xec03 runnable [0x0000700004bd7000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.Net.connect0([email protected]/Native Method)
at sun.nio.ch.Net.connect([email protected]/Net.java:579)
at sun.nio.ch.Net.connect([email protected]/Net.java:586)
at sun.nio.ch.SocketChannelImpl.connect([email protected]/SocketChannelImpl.java:853)
at com.sun.corba.ee.impl.misc.ORBUtility.openSocketChannel(ORBUtility.java:92)
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:306)
at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:229)
at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:254)
at com.sun.corba.ee.impl.transport.ContactInfoImpl.createConnection(ContactInfoImpl.java:108)
at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.beginRequest(ClientRequestDispatcherImpl.java:200)
...
By using tcpdump to capture packets, it was discovered that the kernel was constantly performing TCP retransmissions, with the number of retransmissions being controlled by the kernel parameter net.ipv4.tcp_syn_retries
and using an exponential backoff strategy. On my machine, it takes 130 seconds for the timeout to occur.
Therefore a configurable timeout should be set for the connection process. In fact, ORB already has a configurable property com.sun.corba.ee.transport.ORBTCPConnectTimeouts, but the connection process does not currently utilize this parameter.
This PR introduces a significant enhancement to the socket connection methods, providing more flexibility and control over socket connections.Additionally I add unit tests to ensure the correct functionality of the updated methods. These tests cover both normal operation and timeout scenarios.