Errno::ETIMEDOUT:连接超时 - 连接(2)
在生产中,我偶尔遇到以下错误:
Errno::ETIMEDOUT: Connection timed out - connect(2)
似乎只有当我使用 prawn gem 生成 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
我可以做什么来防止此错误?
In production, I'm occasionally getting the following error:
Errno::ETIMEDOUT: Connection timed out - connect(2)
It only seems to be happening when I generate a PDF using the prawn gem that contains an image that was uploaded by paperclip/aws-sdk to s3. This probably only happens a couple times a week on an action that is used hundreds of times a day (with no issues), but it results in a 500 error when it does fail.
The trace is:
/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'
Line 57:
pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
Setup:
Rails 3.0.10
Ruby 1.8.7EE
Prawn 0.11.1
AWS-SDK 1.3.3
Paperclip 2.5.2
What can I do to prevent this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种选择是捕获异常并重试:
您可能还需要进行一些诊断(记录或生成 Airbrake)来通知您,以便您可以查看是否存在某种故障模式。
One option is to catch the exception and try again:
You may also want to put some diagnostics (either logging or generating an Airbrake) that notifies you so you can see if there is some sort of pattern to the failures.
当使用 aws-sdk 生成新的服务器实例时,我在 Amazon EC2 中遇到了相同的错误。这是我所知道的:
我有一个测试实例状态的函数(sleep_while_not_running):
def sleep_while_not_running(实例)
打印“正在等待系统:”
$stdout.flush
while instance.status != :running
打印 ”。”
$stdout.flush
睡觉 1
结尾
加上“恢复”。
我有一个函数( sleep_while_not_running
发生的情况与您描述的超时错误相同。手动调查,我发现--
a.如果我等到“状态检查”(在管理控制台中)显示新实例已“通过 2/2 检查”,那么我可以使用脚本使用的相同密钥对手动进行 SSH。
b. sleep_while_not_running 检查instance.status(在服务器完全烘焙之前很久就显示“正在运行”。
c.我在 aws-sdk 中找不到用于检查我将在管理控制台中检查的“状态检查”的调用,但我怀疑这就是解决方案存在的地方。
PS 我意识到这不是一个“答案”,但它可能有助于确定解决方案
I have been getting the same error in Amazon EC2 when using aws-sdk to spawn new server instances. Here's what I know:
I have a function (sleep_while_not_running) which tests the instance.status:
def sleep_while_not_running(instance)
print "waiting on system: "
$stdout.flush
while instance.status != :running
print "."
$stdout.flush
sleep 1
end
puts "resuming."
end
After sleep_while_not_running returns, I assume that we should be able to connect (as follows):
What happens is the same time-out error you describe. Investigating manually, I have found that--
a. If I wait until "Status Checks" (in the management console) shows that the new instance has "Passed 2/2 Checks", then I can SSH in manually just fine using the same key pair used by the script.
b. sleep_while_not_running checks instance.status (which says "running" long before the server is fully baked.
c. I can find no call in aws-sdk to check the "status checks" I would check in the management console, but I suspect that is where the solution exists.
P.S. I realize this isn't an "answer" but it may help identify a solution.