繁体   English   中英

Errno :: ETIMEDOUT:连接超时-connect(2)

[英]Errno::ETIMEDOUT: Connection timed out - connect(2)

在生产中, 偶尔会出现以下错误:

Errno::ETIMEDOUT: Connection timed out - connect(2)

当我使用虾宝石生成PDF时,似乎只有这种情况发生了,该虾包含由paperclip / aws-sdk上传到s3的图像。 对于每天使用数百次的操作(可能没有问题),这种情况一周可能只发生几次,但如果操作失败,则会导致500错误。

跟踪是:

/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`initialize'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`connect'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:53:in
`timeout'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:101:in
`timeout'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`connect'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:553:in
`do_start'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:542:in
`start'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:242:in
`open_http'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:616:in
`buffer_open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:164:in
`open_loop'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
`catch'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
`open_loop'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:132:in
`open_uri'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:518:in
`open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:30:in
`open'
....rb:57:in `render_image_to_pdf'

第57行:

pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20

设定:

Rails 3.0.10
Ruby 1.8.7EE
Prawn  0.11.1
AWS-SDK 1.3.3
Paperclip 2.5.2

我该怎么做才能防止此错误?

一种选择是捕获异常,然后重试:

begin
  pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
rescue Errno::ETIMEDOUT
  # try one more time, or use retry with a counter to attempt a limited number of times
  pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
end

您可能还希望放置一些诊断(记录日志或生成Airbrake)来通知您,以便您查看故障是否存在某种形式的模式。

使用aws-sdk生成新服务器实例时,Amazon EC2中出现了相同的错误。 这是我所知道的:

  1. 我有一个用于测试instance.status的函数(sleep_while_not_running):

    def sleep_while_not_running(instance)打印“正在系统上等待:”
    $ instanced.flush时instance.status!=:正在运行打印“。” $ stdout.flush sleep 1结尾将“恢复”。 结束

  2. 在sleep_while_not_running返回之后,我假设我们应该能够连接(如下所示):

     Net::SSH.start(instance.ip_address,'root',:key_data=>[key_pair.private_key]) do |ssh| sleep_while_not_running(instance) puts "testing SSH connectivity." puts ssh.exec("uname -a") puts " " 
  3. 发生的是您描述的相同的超时错误。 通过手动调查,我发现-

    一种。 如果我等到“状态检查”(在管理控制台中)显示新实例具有“通过2/2检查”,则可以使用脚本使用的相同密钥对手动进行SSH正常工作。

    b。 sleep_while_not_running检查instance.status(在完全烘焙服务器之前,它说“正在运行”。

    C。 我无法在aws-sdk中找到任何呼叫来检查“状态检查”,我会在管理控制台中进行检查,但是我怀疑这是解决方案所在。

PS我意识到这不是一个“答案”,但它可能有助于确定解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM