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'
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.
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