我一直在机器上的几台主机上收到此错误,例如:
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>'
不会发生在
之类的其他人身上open('https://twitter.com').read
Ruby 2.4.0来自rbenv和macOS 10.12.3。还测试了Ruby 2.0.0 - macOS上的系统版本。
当我curl
或使用节点request
时,我没有收到任何错误和预期结果。所以这不是被阻止的主机,我的IP也没有被阻止。
尝试重新安装Ruby,重启机器,问题仍然存在。
任何指针?
答案 0 :(得分:11)
看起来这是Ruby如何解析DNS的问题。
添加了require 'resolv-replace'
,现在它立即打开了连接。
来源: https://stackoverflow.com/a/27485369/116925 https://github.com/ruby/ruby/pull/597#issuecomment-40507119
答案 1 :(得分:1)
我从Docker容器中的Rails应用程序收到错误,并且重新启动Docker服务解决了问题:
sudo service docker start
答案 2 :(得分:0)
我遇到了这个问题的另一个原因。有一个网络,其中IPv6被宣布为可路由的,但不是。这导致尝试使用IPv6导致错误。
所以我不得不禁用IPv6。
对于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
require 'resolv-replace'
也有帮助,但我想它只是解析为IPv4,所以我不想以这种方式限制应用程序。