Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

catching timeout exceptions in rails seems to skip rescues and explode "all the way up"

I have a controller:

class EventsController < ApplicationController  
  def index
    begin
      SystemTimer.timeout_after(10, CustomTimeoutError) do
        sleep(11)
      end
    rescue CustomTimeoutError => e
      # swallow
    end
  end
end

For some reason the rescue statement is not catching the timeout but instead its bubbling all the way up to the top, stacktrace gets dumped to console etc. Using the defatult Timeout::Error has the same effect. This happens only on production, not on my development machine. It's as though something else is watching for timeouts and capturing them before it event reaches my rescue.

The stacktrace produced is this:

[GEM_ROOT]/gems/SystemTimer-1.2/lib/system_timer/concurrent_timer_pool.rb:63:in `read_reply'

vendor/gems/redis-1.0.4/lib/redis/client.rb:444:in `process_command'

vendor/gems/redis-1.0.4/lib/redis/client.rb:442:in `map'

vendor/gems/redis-1.0.4/lib/redis/client.rb:442:in `process_command'

vendor/gems/redis-1.0.4/lib/redis/client.rb:431:in `raw_call_command'

vendor/gems/redis-1.0.4/lib/redis/client.rb:452:in `call'

vendor/gems/redis-1.0.4/lib/redis/client.rb:452:in `maybe_lock'

vendor/gems/redis-1.0.4/lib/redis/client.rb:428:in `raw_call_command'

vendor/gems/redis-1.0.4/lib/redis/client.rb:332:in `call_command'

vendor/gems/redis-1.0.4/lib/redis/client.rb:381:in `method_missing'

vendor/gems/ohm-0.0.35/lib/ohm/collection.rb:179:in `size'

vendor/gems/ohm-0.0.35/lib/ohm/collection.rb:65:in `empty?'

vendor/gems/ohm-0.0.35/lib/ohm/collection.rb:33:in `sort'

vendor/gems/ohm-0.0.35/lib/ohm/collection.rb:48:in `first'

vendor/gems/ohm-0.0.35/lib/ohm.rb:129:in `first'

lib/twitter_helper.rb:58:in `get_twitter_searches'

lib/twitter_helper.rb:57:in `each'

lib/twitter_helper.rb:57:in `get_twitter_searches'

lib/twitter_helper.rb:100:in `get_twitter_searches_or_messages'

app/controllers/events_controller.rb:66:in `show'

[GEM_ROOT]/gems/SystemTimer-1.2/lib/system_timer.rb:56:in `timeout_after'

app/controllers/events_controller.rb:65:in `show'

vendor/rails/actionpack/lib/action_controller/base.rb:1331:in `send'
like image 222
Peter Brown Avatar asked Nov 06 '22 14:11

Peter Brown


1 Answers

How did you declare you custom CustomTimeoutError class? Is it a direct descendant of Exception, or of StandardError? I've seen exactly this behavior when descending from Exception, and make a practice of always making my error classes descend from StandardError.

like image 132
Ian Avatar answered Nov 11 '22 02:11

Ian