使用'fb_graph'gem时的HTTPClient :: ConnectTimeoutError

时间:2012-04-11 11:21:20

标签: ruby-on-rails ruby ubuntu

我有一个轨道项目和两个机械装置。一个运行Ubuntu 10.04,另一个运行12.04 beta。我在10.04机器上使用'fb_graph'宝石一切正常,但是当我在12.04机器上做的事情就像

  
    

me = FbGraph :: User.me(token).fetch

  

我得到了

HTTPClient::ConnectTimeoutError: execution expired
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:300:in `connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:300:in `ssl_connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:739:in `block in connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:731:in `connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:594:in `query'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:161:in `query'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient.rb:1060:in `do_get_block'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient.rb:869:in `block in do_request'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient.rb:956:in `protect_keep_alive_disconnected'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient.rb:868:in `do_request'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient.rb:756:in `request'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/httpclient-2.2.4/lib/httpclient.rb:661:in `get'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:49:in `block in get'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:122:in `handle_response'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:48:in `get'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:18:in `fetch'
from (irb):10
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
from /home/jan/.rvm/gems/ruby-1.9.2-p290@ece/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

我不知道为什么会这样,也不知道如何解决。有任何想法吗?谢谢!

2 个答案:

答案 0 :(得分:1)

可能发生的原因是机器的硬件性能和网络性能。

再试几次。有时网络需要时间来加载路由信息,但是一旦加载它就会在下一次加快。这可能不是一个好的生产解决方案,但它可以诊断问题是否使网络路由更加清晰。

这可能是一个真正的网络性能问题。如果您无法调整网络,那可能对您没有帮助。

如果重试有帮助,您可以在代码周围进行重试循环。

(0..2).each do
  begin
    ... #your code goes here
    break
  rescue HTTPClient::ConnectTimeoutError
  end
end

答案 1 :(得分:0)

HTTP请求在服务器和FB之间超时。有关如何配置HTTP客户端超时选项的说明,请参阅此github issue