Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Timeout::timeout not throwing an error

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.

like image 227
codeetcetera Avatar asked Oct 05 '22 00:10

codeetcetera


1 Answers

# 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

like image 197
nyzm Avatar answered Oct 13 '22 12:10

nyzm