94

I have a Tomcat based web application. I am intermittently getting the following exception,

Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:532)
    at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:501)
    at org.apache.coyote.http11.InternalInputBuffer$InputStreamInputBuffer.doRead(InternalInputBuffer.java:563)
    at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:124)
    at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:346)
    at org.apache.coyote.Request.doRead(Request.java:422)
    at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290)
    at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:431)
    at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315)
    at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
    at java.nio.channels.Channels$ReadableByteChannelImpl.read(Channels.java:385)

Unfortunately I don't have access to the client, so I am just trying to confirm on various reasons this can happen:

  1. 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.

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

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

For #1, the initial value I had set was 20 sec, I have bumped this up to 60sec, will test, and see if there are any changes.

Meanwhile, if any of you guys can provide you expert opinion on this, that'l be really helpful. Or for that matter any other reason you can think of which might cause this issue.

1
  • I don't believe it is point 2; however, to confirm you should also set up an AccessLogValve and try and correlate this exception with a specific request. Commented Jun 13, 2013 at 4:34

7 Answers 7

60

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.

Could be in theory, trying to read the next request on a connection, but Tomcat wouldn't log it that way.

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

Sign up to request clarification or add additional context in comments.

7 Comments

For #1 as i said, i have bumped up the connection timeout value of the tomcat connector from 20sec to 60sec. If the timeouts reduce then i'll try changing it to -1 (infinite) for testing and eventually set a more appropriate value. For #2, if suppose the client times out what error/exception should i be expecting on the server?
If the client times out reading the response, the server either won't see anything at all or else may see a 'connection reset'. I wouldn't put the server read timeout too high: it ties up a thread. If a client opens a connection to the server and doesn't send anything immediately it is misbehaving pretty badly.
I do get a "connection reset" once in a while, which i attributed to client timing out (client does have a timeout set, need to figure out what is that). However i have been getting far too many "read timeouts". For which i have bumped up the connection timeout to 60sec. will monitory today if "read timeouts" reduce. My max threads is about 190 and accept count is set to 400, which i plan to reduce to 200. Since no point in having a larger queue, it will just increase the waiting time and hence the latency. Any other changes that you think i can try and might help?
Vicky, the objective isn't to get a clean log file. The objective is to service the clients that aren't misbehaving. The longer you make the read timeout, the longer that thread is tied up waiting for the misbehaving client, so the fewer threads are available to service behaving clients.
Excellent explanation of the general problem, thank you! Does anyone know what file for the tomcat connector property to change that timeout?
|
10

Here are the basic instructions:-

  1. Locate the "server.xml" file in the "conf" folder beneath Tomcat's 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

Comments

3
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.

1 Comment

This is client code for a server-side problem, and actually it occurs when the client is slow sending the complete request.
0

I had the same problem while trying to read the data from the request body. In my case which occurs randomly only to the mobile-based client devices. So I have increased the connectionUploadTimeout to 1min as suggested by this link

Comments

-1

This happenned to my application, actually I was using a single Object which was being called by multiple functions and those were not thread safe.

Something like this :

Class A{
    Object B;
    function1(){
        B.doSomething();
    }
    function2(){
        B.doSomething();
    }
}

As they were not threadsafe, I was getting these errors :

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Socket is closed

and

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out

This is how I fixed it :

Class A{
    function1(){
        Object B;
        B.doSomething();
    }
    function2(){    
        Object B;
        B.doSomething();
    }
}

Hope it helps

1 Comment

The OP is talking about a Tomcat error and is seeking a Tomcat solution.
-5

It means time out from your server response. It causes due to server config and internet response.

1 Comment

No it doesn't mean that. It occurs while the server is reading the request. Read the question.
-13

I am using 11.2 and received timeouts.

I resolved by using the version of jsoup below.

    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.7.2</version>
        <scope>compile</scope>
    </dependency>

1 Comment

The OP is talking about a Tomcat error and is seeking a Tomcat solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.