I'm using heroku to host a ruby on rails application supporting an iOS app. I have a request that might run long and I need to be able to catch the timeout before my request gets killed. I'm using Timeout::timeout(15) to throw an error and handle it appropriately. This works fine on my local and I can see the error being thrown and logged. When I run the same code on heroku no error is logged. I had the same problem when trying to use the rack timeout gem.
Is anyone else having a problem getting timeouts to run on Heroku? I'm on cedar.
# app/controllers/index_controller.rb
require 'timeout'
Class IndexController < ApplicationController
def timeout
begin
status = Timeout::timeout(5) {
sleep(6)
render :text => "will never be rendered"
rescue Timeout::Error
render :text => "timeout handled"
end
end
end
end
# config/routes.rb
match '/timeout' => "index#timeout"
This works fine on heroku: http://young-gorge-7585.herokuapp.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With