4

I have been working on a Jekyll site with no issues for a month, but as of this week, every time I try to run bundle install I get the error Bundler::HTTPError Could not fetch specs from https://rubygems.org. I'm on macOS 10.13, ruby 2.5.1.

Here is my output of ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'

Here's your Ruby and OpenSSL environment:

Ruby:           2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
RubyGems:       2.7.7
Bundler:        1.16.2
Compiled with:  OpenSSL 1.0.2o  27 Mar 2018
Loaded version: OpenSSL 1.0.2o  27 Mar 2018
SSL_CERT_FILE:  /usr/local/etc/openssl/cert.pem
SSL_CERT_DIR:   /usr/local/etc/openssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       failed  ❌  (execution expired)
RubyGems connection to rubygems.org:      failed  ❌  (timed out (https://rubygems.org))
Ruby net/http connection to rubygems.org: failed  ❌

Unfortunately, this Ruby can't connect to rubygems.org. 
Even worse, we're not sure why. 

Here's the full error information:
Net::OpenTimeout: execution expired
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `initialize'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `open'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `block in connect'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:935:in `connect'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:915:in `start'
  (eval):90:in `<main>'
  -e:1:in `eval'
  -e:1:in `<main>'

You might have more luck using Mislav's SSL doctor.rb script. You can get it here:
https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb
Read more about the script and how to use it in this blog post:
https://mislav.net/2013/07/ruby-openssl/

Running the above-mentioned script, I get:

/usr/local/Cellar/ruby/2.5.1/bin/ruby (2.5.1-p57)
OpenSSL 1.0.2o  27 Mar 2018: /usr/local/etc/openssl
SSL_CERT_DIR=""
SSL_CERT_FILE=""

HEAD https://status.github.com:443
#<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>

And finally, openssl s_client -connect rubygems.org:443 -tls1 shows:

CONNECTED(00000005)
140735672206280:error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert protocol version:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.50.2/libressl/ssl/s3_pkt.c:1133:SSL alert number 70
140735672206280:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.50.2/libressl/ssl/s3_pkt.c:522:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 0 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    Start Time: 1530836427
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
---

I know the problem has something to do with my SSL certificate, but I have updated openssl and ruby -ropenssl -e "puts OpenSSL::SSL::SSLContext::METHODS.grep(/.+\d$/).sort" shows that I do have TLSv1_2, so I don't know why it's not working.

I've been racking my brain on this for days - any help would be appreciated! Thanks!

UPDATE: It's not been a couple of weeks and this problem keeps going away and coming back. The other day I restarted my Mac and everything worked fine. Today I've getting a whole new error:

$ ruby -ropen-uri -e 'eval 

open("https://git.io/vQhWq").read'
Here's your Ruby and OpenSSL environment:

Ruby:           2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
RubyGems:       2.7.7
Bundler:        1.16.2
Compiled with:  OpenSSL 1.0.2o  27 Mar 2018
Loaded version: OpenSSL 1.0.2o  27 Mar 2018
SSL_CERT_FILE:  /usr/local/etc/openssl/cert.pem
SSL_CERT_DIR:   /usr/local/etc/openssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       failed  ❌  (execution expired)
RubyGems connection to rubygems.org:      success ✅
Ruby net/http connection to rubygems.org: success ✅

Although your Ruby installation and RubyGems can both connect to rubygems.org, Bundler is having trouble. The most likely way to fix this is to upgrade Bundler by running `gem install bundler`. Run this script again after doing that to make sure everything is all set. If you're still having trouble, check out the troubleshooting guide at http://ruby.to/ssl-check-failed 
(eval):136: warning: constant OpenSSL::SSL::SSLContext::METHODS is deprecated

Then I followed the instructions, ran $ gem install bundler, and get:

ERROR:  Could not find a valid gem 'bundler' (>= 0) in any repository

What is going on?

bildungsroman
  • 437
  • 1
  • 8
  • 17
  • Have you got a proxy in between your machine and the internet? – Keith Mifsud Jul 06 '18 at 06:20
  • @KeithMifsud I do not, and this is all happening from the same location where I was able to connect just last week with no problem. My internet connection in general is great, so it's not that either. – bildungsroman Jul 06 '18 at 16:16
  • this is happening to me but only at home, in my office I can connect to rubygems fine. I haven't found a solution yet – benterprise Feb 08 '19 at 18:08
  • 1
    For me it was an IPv4/IPv6 issue. I followed the instructions from this [answer](https://stackoverflow.com/a/50349235) and it worked. – Levi Jun 27 '20 at 13:06

3 Answers3

6

For Mac OS, changing to the following configuration works.

System Preferences > Network > Advanced > TCP/IP > Configure IPv6: Link-local only

More Info: https://rob.co.bb/posts/2018-10-22-yak-shave-gem-install-issue/

TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
4

I kept getting "Network error while fetching https://rubygems.org/quick/Marshal.4.8/puma-3.11.4.gemspec.rz (execution expired)" when running $bundle with both rvm and brew.

Running $ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'


    Bundler connection to rubygems.org:       failed  ❌  (execution expired)
    RubyGems connection to rubygems.org:      success ✅
    Ruby net/http connection to rubygems.org: success ✅

running $bundle --verbose


    HTTP GET https://index.rubygems.org/versions
    Net::OpenTimeout: execution expired
    /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `initialize'

Which led me to this page: Use Ruby DNS resolver to handle DNS timeout in Net::HTTP which says to add require 'resolv-replace' in your code. Adding this to http.rb resolved my issue, but I know that is not the best solution. I tried everything on this page but adding resolv-replace solved it for me after spending a day on it.

I am using gem -v 2.7.7 , ruby -v ruby 2.5.1p57, and osx 10.9.5.

Tom Sloane
  • 41
  • 1
  • It seems like your issue and the one in the link have more to do with the network connection rather than the SSL cert. I'm on a blazing fast company network, so I know that's definitely not the problem. I can connect to rubygems.org, I just can't get gems because the handshake fails. – bildungsroman Jul 06 '18 at 16:15
  • I am getting `Bundler::HTTPError: Network error while fetching https://index.rubygems.org/versions (execution expired)` when running `bundle --verbose` – bildungsroman Jul 06 '18 at 16:20
1

I also thought about it a lot ( i was running a Ubuntu VortualBox VM). The way to fix it is to simply disable ipv6 (From UI) and restart network.

systemctl restart NetworkManager

MSS
  • 3,306
  • 1
  • 19
  • 50
Kobi Ginon
  • 11
  • 1