Our application is “sometimes” timing out, we have a Java client connecting to a unix daemon and for some reason it is now and again throwing the following error:
SocketException: Cannot establish connection to daemon
java.net.ConnectException: Connection timed out: connect
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at java.nio.channels.SocketChannel.open(Unknown Source)
at ....
at java.lang.Thread.run(Unknown Source)
This stack trace is from the following code:
try
{
InetSocketAddress inetAddress = new InetSocketAddress(InetAddress.getByName(serverName), serverPort);
socketChannel = SocketChannel.open(inetAddress); // <--- I think the problem is here
pipeSck = socketChannel.socket();
}
catch (NoRouteToHostException e)//when the remote host cannot be reached or connection was refused
{
System.err.println("NoRouteToHostException: Cannot establish connection to daemon");
e.printStackTrace();
return 1; /* reply only with error */
}
catch (SocketException e)//when the remote host cannot be reached or connection was refused
{
System.err.println("SocketException: Cannot establish connection to daemon");
e.printStackTrace();
return 1; /* reply only with error */
}
This works 99% of the time… any ideas why we are getting the timeout?
Thanks!
‘Connection timed out’ means either that the network was temporarily down, which is the most likely, or, if it isn’t running on Windows, that the server’s socket backlog queue was full, which could happen under extreme load or denial-of-service attacks.