How do I implement a request timeout in grails?

南笙酒味 提交于 2020-01-25 08:03:31

问题


I'd like to be able to set a configurable (by controller/action) request timeout in grails. The objective is to handle a rare high-load failure mode in a deterministic way. For example, I know that if a given controller/action doesn't return in 30 seconds, then something is horribly wrong and I don't want to keep the user hanging.

I'd like to handle this within the application logic if possible, as there might be reasonable recoveries or messaging depending upon the conditions of the event.

Filters don't work because the time might be reached anywhere in the request processing lifecycle.


回答1:


I don't think this is easily achievable. You're probably limited to the capabilities of the Servlet container you're using. For example, with tomcat you could set a connectionTimeout. Unfortunately, this may not give you the control that you're asking for since the timeout and response are more at the mercy of the container.

There's probably a way you could do it with background threads, timers, interrupts, and some black magic, but that would probably be an ill-advised thing.

A couple mailing list discussions I found on the topic:

  • http://grails.1312388.n4.nabble.com/How-to-change-request-timeout-td1356007.html

    Quote from within by Peter Ledbrook:

    I don't know of a Grails feature for this. It supports the session time out, but not a request time out. Servlet containers have connection timeouts.

  • http://www.mail-archive.com/users@tomcat.apache.org/msg38090.html



来源:https://stackoverflow.com/questions/3705595/how-do-i-implement-a-request-timeout-in-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!