簡體   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