Ruby Net: :Opentimeout: Execution Expired

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

require 'open-uri'
open(').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(').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?

1

3 Answers

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

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

Sources:

I've hit another reason for this issue. Had a network where IPv6 is announced as routable but is not. That lead to IPv6 trying to be used resulting in the error.

So I had to disable IPv6.

For Red Hat Enterprise Linux 7:

# cat /etc/sysctl.d/10-ipv6.conf 
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
# sysctl -p

The require 'resolv-replace' also helped but my guess is that it just resolved to IPv4 instead so I don't want to limit app in such a way.

I received error from rails application in docker container, and restarting docker service solved the problem:

sudo service docker start
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest