I'm trying to understand where I can configure a request timeout for all requests arriving to a servlet of mine (or all of my servlets)? Is that, as I think, a container property? Also, how does this affect different browsers? Do they all comply to the parameter the container dictates? Or maybe the request timeout time isn't even something I can control and each browser decides on this on its own? (Just to be clear I'm not talking about session timeout)
-
1Nice question. I have read your comment to the last answer and I was wondering what approach you have chosen to make sure the request isn't closed. I am trying to make Comet myself and do not know how to make this right. Could you please suggest a solution? Thanks! – Dragos May 16 '12 at 13:54
-
@Dragos I ended usjust implementing a simple Long polling mechanism which returned the request to the user after ~29 seconds (which is less than 30 seconds [the IE limit]). What I'd do now if I was facing the same problem was to try to use the websockets api. – Ittai May 16 '12 at 14:05
-
So you are looking here for a timeout such that "at time x" it flushes the current response and kills the current thread, so that the browser receives data quickly enough? FWIW browsers these days seem to wait "many minutes" on a response... – rogerdpack Jul 28 '17 at 18:45
3 Answers
The timeout from a client (i.e. how long it waits for a response to an HTTP request) is determined at the client. For IE, see this, and for Firefox see this.
You can't control this timeout from the server.

- 95,872
- 14
- 179
- 191
-
First of all thank you for the reply, this cannot be changed programatically on the client side (via JavaScript) right? – Ittai Sep 12 '09 at 10:36
-
You can simply terminate the Java thread handling the request. – Kevin Caravaggio Aug 28 '18 at 01:06
Even though you can't control client timeout, you can make server very impatient :) For example, on Tomcat, you can do this in your connector,
<Connector port="8080"
...
connectionTimeout ="5000"
disableUploadTimeout="false" />
This makes server only wait 5 seconds and close the connection. Browser will get a connection closed error. You can treat it the same as timeout in client.
Of course, this only works if the timeout is caused by the server, not connectivity issues between browser and server.

- 62,887
- 36
- 269
- 388

- 74,484
- 29
- 137
- 169
-
-
2The parameter name is connectionTimeout inside the Connector tag, like this:
– Steven Lizarazo Feb 27 '14 at 16:30
You cannot control the client timeout from the server. However you may be able to send data back to the client every now and then while your long running operation is busy. This will prevent the client from timing out and can be used to display progress to the user etc. Write data to the OutputStream or Writer obtained from the response and call flush to send partial data to the client.

- 9,383
- 9
- 66
- 98
-
how can this partial data be obtained if using xmlHttpRequest? I've read than in IE you cannot access the data until the request is finished – Ittai Sep 12 '09 at 10:51
-
1Yes, but the client shouldn't time out as long as some data is coming in. – Vinay Sajip Sep 12 '09 at 12:22
-
You're right but It's a bit more complicated because I'm implementing Comet so I'll either use 'Long Polling' and thus will need a longer timeout to save requests or use Streaming which is what I though David was suggesting. Anyway thank you. – Ittai Sep 12 '09 at 12:25
-
I agree with David. I had IOException issue with sending large data to the OutputStream when it takes long time to get the entire data set. So, I had to use pagination start to send small amount of the data. Client is happy as long as it gets something. – user3123690 Sep 12 '14 at 16:12