我经常在我的机器上的几个主机上得到这个错误,例如:
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
rbenv中的Ruby 2.4.0和macOS 10.12.3。还测试了Ruby 2.0.0 -macOS上的系统版本。
当我使用curl
或Node的request
时,我没有得到任何错误和预期的结果。所以这不是一个被阻止的主机,我的IP也没有被阻止。
尝试重新安装Ruby,重新启动机器,问题仍然发生。
有什么建议吗?
3条答案
按热度按时间ruoxqz4g1#
看起来这是一个Ruby如何解析DNS的问题。
添加了
require 'resolv-replace'
,现在它立即打开连接。来源:https://stackoverflow.com/a/27485369/116925 https://github.com/ruby/ruby/pull/597#issuecomment-40507119
mqkwyuun2#
我找到了这个问题的另一个原因。有一个网络,其中IPv6被宣布为可路由的,但不是。这导致IPv6尝试使用导致错误。
所以我不得不禁用IPv6。
对于Red Hat Enterprise Linux 7:
require 'resolv-replace'
也有帮助,但我的猜测是,它只是解决了IPv4,而不是,所以我不想限制应用程序在这样一种方式。wa7juj8i3#
我在docker容器中收到rails应用程序的错误,重新启动docker服务解决了这个问题: