isaac.hazan
isaac.hazan

Reputation: 3874

Does Tomcat connection timeout triggers a 500 to the HTTP client?

In my setup i see intermittently a number of errors as follows:

2016-07-07 12:22:04,248 ERROR  [com.biltz.krieg.endpoints.controllers.ControllerBase] (http-nio-8080-exec-25) Caught Exception:
java.io.EOFException: Unexpected EOF read on the socket
        at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:152)
        at org.apache.coyote.http11.InternalNioInputBuffer$SocketInputBuffer.doRead(InternalNioInputBuffer.java:177)
        at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:110)
        at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:413)
        at org.apache.coyote.Request.doRead(Request.java:460)

The times of those errors coincide with the access log showing the following:

[07/Jul/2016:12:36:36] 172.31.2.246 POST /v1/blitz 500 59.499 133
[07/Jul/2016:12:37:29] 172.31.2.246 POST /v1/blitz 500 59.186 133
[07/Jul/2016:12:39:41] 172.31.2.246 POST /v1/blitz 500 59.889 133

The interesting about the above it every request that triggered a 500 from the server took about 60 seconds to be processed.

60 seconds is how Tomcat connection timeout is configured:

 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="60000"
               redirectPort="8443" />

So it seems really related to the this timeout but I don't understand why as the documentation about the connection timeout says this

The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds).

The above means to me that after this timeout occurs, the TCP/HTTP connection would be closed without sending anything. Am i wrong?

Does Tomcat connection timeout triggers a 500 to the HTTP client?

Upvotes: 0

Views: 4255

Answers (1)

jjcarver
jjcarver

Reputation: 146

Are you using Apache as a front end for Tomcat? I had a similar problem, and adjusting the timeout in the Apache configuration solved the problem.

Specifically, I am running Tomcat 6.0.24 with incoming requests redirected from port 80 by Apache 2.2.15 on a CentOS 6.6 virtual machine. I adjusted this line in my Apache config file (/etc/httpd/conf/httpd.conf):

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 60

The default is apparently 60 seconds. I increased it to 120 seconds. This solved my problem.

Just to be clear, I did not modify the <Connector> element in my Tomcat configuration file (/etc/tomcat6/server.xml) as you mentioned. I left it at the default, which is apparently 20 seconds for release versions of Tomcat:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

This implies that the 500 errors I was receiving (and presumably yours as well) were not caused by this timeout. In particular, although I left my Tomcat timeout at the default of 20 seconds here, I have services that grind for over a minute and still return a good response. It was only the Apache configuration that was killing them if they went over 60 seconds.

Upvotes: 1

Related Questions