SocketTimeoutException connect time out : how do i debug my server for root cause

user2562732 picture user2562732 · Nov 2, 2013 · Viewed 11.9k times · Source

I am trying to call my remote tomcat server from java client but i intermittently get SocketTimeoutException: connection time out. (http://docs.oracle.com/javase/7/docs/api/java/net/SocketTimeoutException.html)

here is the stack trace

Caused by: java.net.SocketTimeoutException: connect timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:382)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:241)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:228)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:365)
        at java.net.Socket.connect(Socket.java:527)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
        at org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory.createSocket(EasySSLProtocolSocketFactory.java:189)
        at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)

It is not consistent, it goes away after my code makes multiple attempt to connect.

i understand what socketTimeout means, I am not getting read time out but connect time out, which means client fails to setup tcp connection with the server.Meaning server just disregards the clients attempt to connect it, as either its not available or too busy doing something else on that port. I know my server is reachable and up and running.

apparently my attempt to connect to the server is being refused, i want to figure out why? how do i get started? what should i look for? my server runs on redhat linux box running on an EC2 instance, is there a way i can look at why my connection is being refused?

Answer

guilespi picture guilespi · Nov 2, 2013

Probable cause is other process or Tomcat itself consuming resources makes the app unresponsive.

Start monitoring server resources:

  • CPU
  • Memory
  • Network activity
  • Open handles(are you running on linux?)

Intermittence can be explained because only when the server is under load connection fails.

You can also try to increase connection timeout on the server as in this previous question.