Ubuntu上的Net :: OpenTimeout,带有Ruby 2.3.3和Rails 5

时间:2016-12-22 18:22:37

标签: ruby-on-rails ubuntu-12.04 ruby-on-rails-5 ruby-2.3

我正在将Rails应用程序从Rails 4.2升级到5,从Ruby 2.2.3升级到2.3.3。我们使用的一个delayed_job进程缓存来自Web上其他地方的图像。缓存的图像通过s3支持的回形针存储,但似乎它是间歇性失败的读取 - 每个作业运行缓存大约40-60个图像,具有适当的限制,因此缓存不会使服务器沉没,大约80数据的各个部分的总作业运行 - 每个作业开始,缓存一些图像,然后用下面的堆栈跟踪炸毁。

值得注意的是:

  • 这发生在我们的登台服务器上,该服务器运行的是Ubuntu 12.04.5 LTS;在Mac OS X上,我在开发过程中不会发生这种情况
  • 根据Net:OpenTimeout错误的其他讨论,我尝试在登台服务器上禁用IPv6;这似乎可以防止错误,但似乎是一个kludge
  • 这不是在服务器上运行Ruby 2.2.3和Rails 4.2.7,而是使用Ruby 2.3.3和Rails 5.0.1;除了这些更新(以及在发生错误后更改IPv6设置),我没有对服务器配置进行任何更改
  • 使用相同的代码进行初始测试,Rails 5.0.1和Ruby 2.2.3表明该问题可能只发生在Ruby 2.3下(很难说在这一点上,它成功地运行了80个工作中的10个)

任何建议表示赞赏。堆栈跟踪指向第1041行,这是开放(URI.parse ...)行,而不是file.write行,所以我认为将图像缓存,而不是将其写入s3是​​一个问题。

def image_from_url(url, type)

  file = Tempfile.new("tmp_image_"+type+[*1..10000].sample.to_s+".jpg")
  file.binmode

  encoded_url = URI.encode(url)
  open(URI.parse(encoded_url)) do |data|
    file.write data.read
  end

  file.rewind

  if type == "profile"
    self.profile_picture = file
  else
    self.main_picture = file
  end
end

堆栈跟踪:

Net::OpenTimeout: execution expired
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:880:in `initialize'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:880:in `open'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:319:in `open_http'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:737:in `buffer_open'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:212:in `block in open_loop'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:210:in `catch'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:210:in `open_loop'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:151:in `open_uri'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:717:in `open'
from /home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/open-uri.rb:31:in `open'
from /home/user/public_html/.../apps/.../releases/20161221214252/app/models/base_ad.rb:1041:in `image_from_url'

0 个答案:

没有答案