Reputation:
I am using the Rack-timeout gem and a Rack::Timeout::RequestTimeoutException occurs. I did no configuration outside of putting this gem into my gemfile.
How do I handle these exceptions so that they don't stop the normal app's procedure but instead just log and let me know about them?
Upvotes: 4
Views: 5970
Reputation: 21
to change the timeout, run
export RACK_TIMEOUT_SERVICE_TIMEOUT=30
Upvotes: 0
Reputation: 2792
You can catch the exception in your application with
# in your app/controllers/application_controller.rb
rescue_from Rack::Timeout::RequestTimeoutException do |exception|
# do something
end
But as it's an exception I don't believe it's possible to return execution to where it was interrupted.
However, timeout also drops a log message every 1 second like this:
source=rack-timeout id=1123e70d486cbca9796077dc96279126 timeout=20000ms
service=1018ms state=active
Perhaps you could increase the interval of these to, say 5 seconds, and change the timeout to something high like 120 seconds, that way it's unlikely to actually interrupt anything, but you will get log messages to tell you that something is running long.
Upvotes: 4
Reputation: 14580
The whole purpose of that gem is to raise exceptions after a timeout
"Abort requests that are taking too long; an exception is raised."
If that's not what you want to do, perhaps you shouldn't be using that particular gem? Random google hit https://github.com/moove-it/rack-slow-log
Upvotes: 3