简体   繁体   English

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

[英]Errno::ETIMEDOUT: Connection timed out - connect(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. 当我使用虾宝石生成PDF时,似乎只有这种情况发生了,该虾包含由paperclip / aws-sdk上传到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. 对于每天使用数百次的操作(可能没有问题),这种情况一周可能只发生几次,但如果操作失败,则会导致500错误。

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: 第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? 我该怎么做才能防止此错误?

One option is to catch the exception and try again: 一种选择是捕获异常,然后重试:

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

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

I have been getting the same error in Amazon EC2 when using aws-sdk to spawn new server instances. 使用aws-sdk生成新服务器实例时,Amazon EC2中出现了相同的错误。 Here's what I know: 这是我所知道的:

  1. I have a function (sleep_while_not_running) which tests the instance.status: 我有一个用于测试instance.status的函数(sleep_while_not_running):

    def sleep_while_not_running(instance) print "waiting on system: " def sleep_while_not_running(instance)打印“正在系统上等待:”
    $stdout.flush while instance.status != :running print "." $ instanced.flush时instance.status!=:正在运行打印“。” $stdout.flush sleep 1 end puts "resuming." $ stdout.flush sleep 1结尾将“恢复”。 end 结束

  2. After sleep_while_not_running returns, I assume that we should be able to connect (as follows): 在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. 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. 如果我等到“状态检查”(在管理控制台中)显示新实例具有“通过2/2检查”,则可以使用脚本使用的相同密钥对手动进行SSH正常工作。

    b. b。 sleep_while_not_running checks instance.status (which says "running" long before the server is fully baked. sleep_while_not_running检查instance.status(在完全烘焙服务器之前,它说“正在运行”。

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

PS I realize this isn't an "answer" but it may help identify a solution. PS我意识到这不是一个“答案”,但它可能有助于确定解决方案。

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

相关问题 操作超时 - 连接(2)(Errno :: ETIMEDOUT) - Operation timed out - connect(2) (Errno::ETIMEDOUT) 我无法生成rails项目,Gem :: RemoteFetcher :: FetchError:Errno :: ETIMEDOUT:操作超时 - 连接(2) - I can't generate rails project, Gem::RemoteFetcher::FetchError: Errno::ETIMEDOUT: Operation timed out - connect(2) PostgreSQL:无法连接到服务器:连接超时 - PostgreSQL: could not connect to server: Connection timed out 连接被拒绝 - 连接(2)(Errno :: ECONNREFUSED) - Connection refused - connect(2) (Errno::ECONNREFUSED) REST服务连接超时 - Connection timed out with REST service 安装导轨中的连接超时 - Connection Timed out in Installing rails Appfog + Rails 3 + Postgresql + IronWorker =>无法连接到服务器:连接超时(PG :: Error) - Appfog + Rails 3 + Postgresql + IronWorker => could not connect to server: Connection timed out (PG::Error) Heroku + Sendgrid = Errno :: ECONNREFUSED(连接被拒绝-connect(2)) - Heroku + Sendgrid = Errno::ECONNREFUSED (Connection refused - connect(2)) Ruby-连接被拒绝-connect(2)(Errno :: ECONNREFUSED) - Ruby - Connection refused - connect(2) (Errno::ECONNREFUSED) 发布和Errno :: ECONNREFUSED(连接被拒绝 - 连接(2)) - Post and Errno::ECONNREFUSED (Connection refused - connect(2))
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM