title: Rescue from Errno::ECONNRESET when running bundle install
body: <p>I'm working on a gem to scaffold a new Rails app with a variety of dependencies. When running <code>bundle install</code>, I periodically hit this error:</p>
  
  <pre><code>Gem::RemoteFetcher::FetchError: Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://rubygems.org/gems/&lt;gem_name&gt;.gem)
  An error occurred while installing &lt;gem_name&gt; (x.x.x), and Bundler cannot continue.
  Make sure that `gem install &lt;gem_name&gt; -v 'x.x.x'` succeeds before bundling.
  </code></pre>
  
  <p>If I just new up a Rails app and hit this, the error is easily remedied by running <code>bundle install</code> a few times until everything installs without failure, however, in the generator gem, I need to be able to catch this error and retry <code>bundle install</code>. I would expect something along the lines of this to work, but it doesn't:</p>
  
  <pre><code>begin
    run 'bundle install'
  rescue Errno::ECONNRESET =&gt; e
    puts "Retrying... Error caught: #{e}"
    count += 1
    retry unless count &gt; 10
    puts "Tried to `bundle install` 10 times: #{e}"
  end
  </code></pre>
  
  <p>Help?</p>