Net::OpenTimeout on Ubuntu with Ruby 2.3.3 and Rails 5

571 views Asked by At

I'm in the process of upgrading our Rails app from Rails 4.2 to 5 and from Ruby 2.2.3 to 2.3.3. One of the delayed_job processes we use caches images from elsewhere on the web. The cached images are stored via s3-backed paperclip, but it seems like it's the read that has been failing intermittently—each job run caches about 40-60 images, with appropriate throttling so the caching doesn't sink the server, and about 80 total job runs for various segments of the data—and each job starts, caches some number of images, and then blows up with the stack trace below.

Of note:

  • this is happening on our staging server, which is running Ubuntu 12.04.5 LTS; it does not happen to me in development, on Mac OS X
  • per the other discussions of Net:OpenTimeout errors here, I've tried disabling IPv6 on the staging server; this seems to prevent the error, but seems like a kludge
  • this was not happening running Ruby 2.2.3 and Rails 4.2.7 on the server but is with Ruby 2.3.3 and Rails 5.0.1; other than those updates (and changing the IPv6 setting after the error occurred), I haven't made any changes to server config
  • initial testing with the same code, Rails 5.0.1, and Ruby 2.2.3 suggests that the issue may only occur under Ruby 2.3 (tough to say at this point, it's run about 10 of 80 jobs successfully)

Any suggestions appreciated. The stack trace is pointing at line 1041, which is the open(URI.parse...) line, not the file.write line, so I think it's an issue getting the image to cache, not writing it to 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

And the stack trace:

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

There are 0 answers