sockets – java.net.SocketTimeoutException: Read timed out under Tomcat

sockets – java.net.SocketTimeoutException: Read timed out under Tomcat

Server is trying to read data from the request, but its taking longer than the timeout value for the data to arrive from the client. Timeout here would typically be tomcat connector -> connectionTimeout attribute.

Correct.

Client has a read timeout set, and server is taking longer than that to respond.

No. That would cause a timeout at the client.

One of the threads i went through, said this can happen with high concurrency and if the keepalive is enabled.

That is obviously guesswork, and completely incorrect. It happens if and only if no data arrives within the timeout. Period. Load and keepalive and concurrency have nothing to do with it whatsoever.

It just means the client isnt sending. You dont need to worry about it. Browser clients come and go in all sorts of strange ways.

Here are the basic instructions:-

  1. Locate the server.xml file in the conf folder beneath Tomcats base directory (i.e. %CATALINA_HOME%/conf/server.xml).
  2. Open the file in an editor and search for <Connector.
  3. Locate the relevant connector that is timing out – this will typically be the HTTP connector, i.e. the one with protocol=HTTP/1.1.
  4. If a connectionTimeout value is set on the connector, it may need to be increased – e.g. from 20000 milliseconds (= 20 seconds) to 120000 milliseconds (= 2 minutes). If no connectionTimeout property value is set on the connector, the default is 60 seconds – if this is insufficient, the property may need to be added.
  5. Restart Tomcat

sockets – java.net.SocketTimeoutException: Read timed out under Tomcat

Connection.Response resp = Jsoup.connect(url) //
                .timeout(20000) //
                .method(Connection.Method.GET) //
                .execute();

actually, the error occurs when you have slow internet so try to maximize the timeout time and then your code will definitely work as it works for me.

Leave a Reply

Your email address will not be published.