How to control timeout exceptions.

Discussion in 'Ruby' started by Junaid Junaidi, Jul 23, 2009.

  1. This is code that i am using for fetching updates from twitter. I used
    SystemTimer gem from
    thoughtwork( to ensure that we
    don't get anymore timeout exception and crashed page.As article
    ( points out weaknesses of
    timeout.rb implemented in ruby 1.8. We are using ruby 1.8 in production.
    After system_timer we also handle "rescue Twitter::Error" but they also
    didn't work. I know we can also option to configure timeout in the http
    client library but i think these both should work fine.

    We are using rails 2.2.2 and ruby 1.8.6. Here is my code.


    SystemTimer.timeout(TWITTER_SERVICE_TIMEOUT) do
    c = =>,:password => profile_twitter.password)
    my_timeline = c.timeline_for:)me, :since => 30.minutes.ago)
    rescue Twitter::RESTError => re

    rescue Timeout::Error
    #my_timeline = nil

    Exception i got mostly

    /usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
    /usr/lib/ruby/1.8/net/http.rb:560:in `open'
    /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    /usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
    /usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
    /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
    /usr/lib/ruby/1.8/net/http.rb:542:in `start'
    Junaid Junaidi, Jul 23, 2009
    1. Advertisements

  2. Junaid Junaidi

    Robert Dober Guest

    Robert Dober, Jul 23, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.