Usecase:
Building a rest api with spring boot. I want to set timeout for 30 seconds. but it waits infinitely. Expecting it to timeout in 30 seconds.
server.tomcat.connection-timeout is not working in 2.1.15.RELEASE. Tried setting it in application.ym,application.properties and also setting with system.setproperty.
None of them are working.
Example:
System.setProperty("server.tomcat.connection-timeout","30s");
Comment From: wilkinsona
Thanks for the report, @itdeepdive.
The server.timcat.connection-timeout
property configures the connectionTimeout
on Tomcat's connector. Tomcat's documentation describes this property as follows:
The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented.
When you say that the configuration property is not working, what behaviour have you seen and what behaviour did you expect to see?
Comment From: itdeepdive
@wilkinsona Thanks for quick reply. I want the rest api request to timeout in 30 seconds currently but it never times out.
Comment From: wilkinsona
Thanks. I’m not sure what behaviour you want when you say “request to timeout in 30 seconds “. As you have noticed, setting the connection timeout will only result in a timeout when the client connects but is then too slow to send its request.
If you want the client to wait for a maximum of 30 seconds for a response you will have to configure that on the client-side. If you want the server-side to only spend a maximum of 30 seconds handling the request there is no way to guarantee that as you cannot force the thread that is handling the request to stop.
Without knowing more about the exact behaviour that you want, it’s hard to offer any more guidance. Setting spring.mvc.async.request-timeout
to 30 seconds and using Spring MVC’s asynchronous support (returning a `DeferredResult, for example) may be an option.
If you have any further questions, please follow up on Stack Overflow or Gitter with a detailed description of exactly what behaviour you want from the perspective of both the client and the server. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.