Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "SocketTimeoutException connect time out" and how do I fix it?

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?

like image 414
user2562732 Avatar asked Sep 17 '25 10:09

user2562732


1 Answers

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.

like image 198
guilespi Avatar answered Sep 19 '25 02:09

guilespi