tomcatserver.xml

Tomcat: Setting connectionTimeout in server.xml not effective


I am updating the default entry in the conf/server.xml in Tomcat 9 to timeout on a request after 1 second, but am not seeing the effects of this change in the browser.

I am expecting to see a 500 Internal Server Error in the F12 Developer Tools Network Tab, but the status is coming back as 200 on the requests that take over 1 second.

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

I have checked that the server.xml is being read by setting connectionTimeout to a (an invalid value) and see a warning regarding this setting in the logs. Furthermore, I am making sure the desired server.xml is used by issuing the command catalina.bat start -config \conf\server.xml.

  1. Do I have the right attribute(connectionTimeout) for setting the timeout for a request?
  2. Is there something else I need to set?
  3. Is there a way for me to check to see if connectionTimeout is set correctly on the running Tomcat instance?

Please let me know.


Solution

  • I'm not sure what you're trying to do exactly. It seems like you want to set a timeout on the time it takes your server to reply to a request.

    So what roughly happens:

    1. Browser sets up TCP connection with your server
    2. Browser sends html request
    3. Your server receives the request and starts processing it
    4. Your server starts sending a response
    5. Your server finishes sending a response

    As far as I know, connectiontimeout is what happens between point 1 and 2 (again, roughly, the details are slightly more complicated). So the response time of your server does not matter here. It's only the time between when the browser sets up a connection with your server and when it sends the request. So if you want something based on your server response time, you are not using the right attribute.

    Now, usually, people don't really set timeouts on responses, but the consumer (in this case the browser) sets the timeout. My browser, for example, sets a timeout of 300 seconds. I've looked around in the documentation a bit, and you might be able to set a replytimeout on the workers, but I haven't tested this and I'm not sure it will work.

    More to the point, why do you want to set a timeout on the response? Is there some call (database, webservice, ...) you make while processing the request that could take very long? In that case, you should just set a timeout on that call. This will allow you to log an error and just instantly give the 500 error. If you just happen to be processing forever, you probably want to interrupt and stop the process and return an error and again potentially log information so you know where it's going wrong. In conclusion, control waiting on feedback from external resources and your processing time in your web application instead of trying to set a reponse timeout on your web server.