2

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.

apandit
  • 808
  • 1
  • 7
  • 16

2 Answers2

5

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.

HSquirrel
  • 839
  • 4
  • 16
  • Thanks! This explains why I wasn't seeing an effect between steps 3 and 4. – apandit Jun 20 '17 at 17:51
  • By the way, I was seeing a 500 error happening at 60 seconds from the time the request is sent to when the first byte of the response is received. I thought that the connectionTimeout was kicking in for Tomcat. I was trying to verify this by setting the timeout really low and seeing if that 60 sec interval changed. – apandit Jun 20 '17 at 17:54
  • Let me see if I understand this correctly: you use a browser to access your site and after 60 seconds you get a 500 error. Because of this error, you tried to change the connectionTimeout. This did not fix the problem and hence your question on stackoverflow. Did I get that correctly? If I understood correctly, it's likely (other causes possible) to be caused by an uncaught exception in your application code. You should be able to find more information in the server logs (depending on how you set up your logging). Default server log location is /var/log/tomcat6/catalina.out. – HSquirrel Jun 21 '17 at 07:48
0

The status is coming back as 200 for the requests that take over 1 second.

So? You seem to have a mistaken idea of what this setting does. From the documentation:

connectionTimeout
The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented.

You wrote:

[I] am not seeing the effects of this change in the browser.

You can't possibly see the effect of this change in the browser, because you can't control how long the browser takes to present the request URI line after creating the connection.

I can't answer your three questions until you define what you mean by 'timeout for a request'.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    The documentation you refer to also says "Unless `disableUploadTimeout` is set to false, this timeout will also be used when reading the request body (if any)" for the `connectionTimeout` description. So, since I am not setting `disableUploadTimeout` to false and this attribute is by default true, I am expecting Tomcat to timeout and generate a 500 error after 1 sec as per the `connectionTimeout` setting. – apandit Jun 14 '17 at 11:08
  • The timeout won't happen unless you don't send anything for over a second. How are you preventing the browser from doing that? – user207421 Jun 14 '17 at 21:15
  • So, are you saying that Tomcat needs to detect a break in a request's transmission for over 1 second in order for me to observe the timeout occur? – apandit Jun 15 '17 at 10:13