Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:03:40+00:00 2026-05-24T13:03:40+00:00

I need to rescue a Timeout::Error raised from a the Redis library but i’m

  • 0

I need to rescue a Timeout::Error raised from a the Redis library but i’m running into a problem, rescuing that specific class doesn’t seem to work.

begin
  Redis.new( { :host => "127.0.0.X" } )
rescue Timeout::Error => ex
end

=> Timeout::Error: Timeout::Error from /Users/me/.rvm/gems/ree-1.8.7-2011.03@gowalla/gems/redis-2.2.0/lib/redis/connection/hiredis.rb:23:in `connect'

When i try to rescue Exception it still doesn’t work

begin
  Redis.new( { :host => "127.0.0.X" } )
rescue Exception => ex
end

=> Timeout::Error: Timeout::Error from /Users/me/.rvm/gems/ree-1.8.7-2011.03@gowalla/gems/redis-2.2.0/lib/redis/connection/hiredis.rb:23:in `connect'

If i try to raise the exception manually, i can rescue it but don’t know why i can’t rescue it when it’s called from within the Redis Gem (2.2.0).

begin
  raise Timeout::Error
rescue Timeout::Error => ex
  puts ex 
end

Timeout::Error
=> nil 

Any clue how to rescue this exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:03:42+00:00Added an answer on May 24, 2026 at 1:03 pm

    You ran this code in irb, right? The exception you are getting is not actually being raised by Redis.new. It is being raised by the inspect method, which irb calls to show you the value of the expression you just typed.

    Just look at the stack trace (I shortened the paths to make it legible):

    ruby-1.8.7-p330 :009 >   Redis.new(:host => "google.com")
    Timeout::Error: time's up!
        from /.../SystemTimer-1.2.3/lib/system_timer/concurrent_timer_pool.rb:63:in `trigger_next_expired_timer_at'
        from /.../SystemTimer-1.2.3/lib/system_timer/concurrent_timer_pool.rb:68:in `trigger_next_expired_timer'
        from /.../SystemTimer-1.2.3/lib/system_timer.rb:85:in `install_ruby_sigalrm_handler'
        from /..../lib/ruby/1.8/monitor.rb:242:in `synchronize'
        from /.../SystemTimer-1.2.3/lib/system_timer.rb:83:in `install_ruby_sigalrm_handler'
        from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `call'
        from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `initialize'
        from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `new'
        from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `connect'
        from /.../SystemTimer-1.2.3/lib/system_timer.rb:60:in `timeout_after'
        from /.../redis-2.2.2/lib/redis/connection/ruby.rb:115:in `with_timeout'
        from /.../redis-2.2.2/lib/redis/connection/ruby.rb:25:in `connect'
        from /.../redis-2.2.2/lib/redis/client.rb:227:in `establish_connection'
        from /.../redis-2.2.2/lib/redis/client.rb:23:in `connect'
        from /.../redis-2.2.2/lib/redis/client.rb:247:in `ensure_connected'
        from /.../redis-2.2.2/lib/redis/client.rb:137:in `process'
    ... 2 levels...
        from /.../redis-2.2.2/lib/redis/client.rb:46:in `call'
        from /.../redis-2.2.2/lib/redis.rb:90:in `info'
        from /..../lib/ruby/1.8/monitor.rb:242:in `synchronize'
        from /.../redis-2.2.2/lib/redis.rb:89:in `info'
        from /.../redis-2.2.2/lib/redis.rb:1075:in `inspect'
        from /..../lib/ruby/1.8/monitor.rb:242:in `synchronize'
        from /.../redis-2.2.2/lib/redis.rb:1074:in `inspect'
        from /..../lib/ruby/1.8/irb.rb:310:in `output_value'
        from /..../lib/ruby/1.8/irb.rb:159:in `eval_input'
        from /..../lib/ruby/1.8/irb.rb:271:in `signal_status'
        from /..../lib/ruby/1.8/irb.rb:155:in `eval_input'
        from /..../lib/ruby/1.8/irb.rb:154:in `eval_input'
        from /..../lib/ruby/1.8/irb.rb:71:in `start'
        from /..../lib/ruby/1.8/irb.rb:70:in `catch'
        from /..../lib/ruby/1.8/irb.rb:70:in `start'
        from /..../bin/irb:17
    

    As you can see above, the exception occurs inside inspect, not Redis.new. When you call inspect on a Redis object, instead of just printing out its state it actually does a lot of things. In this case, inspect attempts to connect to the server and throws an exception when that times out. This seems like a very bad design to me and maybe we should file a bug report to the maintainers of the Redis gem.

    This leads to some interesting behavior in IRB:

    • Typing Redis.new(:host => "google.com") results in an exception as shown above
    • Typing Redis.new(:host => "google.com"); 'hello' results in ‘=> "hello"‘

    If you want to catch this exception, try calling ensure_connected inside your begin/rescue/end block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement a feature that lets resque jobs timeout if they are
I need to rescue from 'Errno::ENOENT' in a Ruby on Rails 3.0.4 application. I
I am parsing the following CSV lines. I need to rescue malformed lines that
Need help with a query that I wrote: I have three tables Company id
I have a project where I need to work on a new feature that
I'm a jQuery beginner, but I need to style the front-end of a CMS
Using Capybara, I need to assert that a form element is not present, for
I'm working with DelayedJob and I need to override a method that I thought
After creating a file and populating data into it, before close, need read part
I am trying to capture the URL that produced a routing error. My end

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.