2

我正在将我们的 Rails 应用程序从 Rails 4.2 升级到 5 以及从 Ruby 2.2.3 升级到 2.3.3。我们使用的 delay_job 进程之一缓存来自网络上其他地方的图像。缓存的图像是通过 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 行,这是 open(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'
4

0 回答 0