Arup Rakshit
Arup Rakshit

Reputation: 118271

Bundler::HTTPError Could not fetch specs from http://rubygems.org/

I am getting the following error when trying to deploy to production.

-----> Installing gem dependencies using Bundler
       The git source `git://github.com/radar/paranoia.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
       The git source `git://github.com/zpaulovics/datetimepicker-rails.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
       Warning: the running version of Bundler (1.13.6) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       Fetching source index from http://rubygems.org/

       Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from http://rubygems.org/
       Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from http://rubygems.org/
       Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from http://rubygems.org/Could not fetch specs from http://rubygems.org/
-----> Deploy finished

In my Gemfile I have:

source 'http://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.7.1'
#...

I tried as bundler troubleshoot guide asked to do...

ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'
Here's your Ruby and OpenSSL environment:
Ruby:           2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
RubyGems:       2.5.1
Bundler:        1.13.6
Compiled with:  OpenSSL 1.0.1f 6 Jan 2014
Loaded version: OpenSSL 1.0.1f 6 Jan 2014
SSL_CERT_FILE:  /usr/lib/ssl/cert.pem
SSL_CERT_DIR:   /usr/lib/ssl/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
  /home/docking_prod/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http.rb:880:in `initialize'
  /home/docking_prod/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http.rb:880:in `open'
  /home/docking_prod/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
  /home/docking_prod/.rbenv/versions/2.3.1/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
  /home/docking_prod/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http.rb:878:in `connect'
  /home/docking_prod/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
  /home/docking_prod/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http.rb:858:in `start'
  (eval):101: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/

How can I fix this? What else information I need to provide please let me know.

EDIT

I just ran the doctor.rb script and found..

docking_prod@app:~$ ruby doctor.rb 
/home/docking_prod/.rbenv/versions/2.3.1/bin/ruby (2.3.1-p112)
OpenSSL 1.0.1f 6 Jan 2014: /usr/lib/ssl
SSL_CERT_DIR=""
SSL_CERT_FILE=""

HEAD https://status.github.com:443
OK

Upvotes: 0

Views: 2864

Answers (2)

leompeters
leompeters

Reputation: 1035

I could solve this issue adding :ipv4_fallback_enabled: true to ~/.gemrc.

Upvotes: 1

Rakesh
Rakesh

Reputation: 841

I have also faced similar issue

While gem is stalling, I ran netstat

netstat -tnp | grep ruby

and I got below output

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      1 2401:4900:188e:90:56960 2a04:4e42:600::644:443  SYN_SENT    4096/ruby

and 2a04:4e42:600::644:443 is one of the addresses of api.rubygems.org

My conclusion is that gem uses IPv6 when it can.

So disabling IPV6 on my workstation fixed it.

Below are the steps to temporarily disabled IPV6 on Ubuntu. IPV6 will be enabled by When we restart system system after restart.

sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1

Note: Use sudo for permission denied issue.

Upvotes: 1

Related Questions