ruby

Ruby Net::OpenTimeout: execution expired


I'm consistently getting this error on several hosts on my machine, e.g.:

require 'open-uri'
open('https://google.com').read


Net::OpenTimeout: execution expired
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:904:in `initialize'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:904:in `open'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:904:in `block in connect'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/timeout.rb:103:in `timeout'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:902:in `connect'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:887:in `do_start'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:876:in `start'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:323:in `open_http'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:741:in `buffer_open'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:212:in `block in open_loop'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:210:in `catch'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:210:in `open_loop'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:151:in `open_uri'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:721:in `open'
    from /usr/local/opt/rbenv/versions/2.4.0/lib/ruby/2.4.0/open-uri.rb:35:in `open'
    from (irb):3
    from /usr/local/opt/rbenv/versions/2.4.0/bin/irb:11:in `<main>'

Doesn't happen on others such as

open('https://twitter.com').read

Ruby 2.4.0 from rbenv and macOS 10.12.3. Tested also with Ruby 2.0.0 - the system version on macOS.

I get no error, and expected results when I curl or use Node's request. So this is not a blocked host, and my IP isn't blocked either.

Tried to reinstall Ruby, restart machine, and issue still occurs.

Any pointers?


Solution

  • Looks like it's a an issue with how Ruby resolves DNS.

    Added require 'resolv-replace' and now it's opening connections immediately.

    Sources: https://stackoverflow.com/a/27485369/116925 https://github.com/ruby/ruby/pull/597#issuecomment-40507119