Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Retry fetch specs with --retry #2601

Merged
merged 2 commits into from Sep 28, 2013
Merged

Conversation

schneems
Copy link
Contributor

This PR adds a general purpose Retry class that can be re-used where-ever retry code is needed!

It also allows you to call bundle install --retry 3 which will attempt to connect to ruby gems 3 times before failing, and emit a warning message each time.

Bundler::Retry.new("something", 3).attempts do
  # code to retry here
end

end

def keep_trying?
return true if @failed.nil?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to initialize @falied as false and remove this condition?

other than that, your PR looks great! Loved the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @failed is false then run never gets called at all. I'm using it here as a special case to run the first time. I guess I could add a return true if current_attempt == 0 instead, which might be a bit more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use current_attempt.zero? which makes more sense syntactically.

@xaviershay
Copy link
Contributor

I'm curious what the motivation for this is. Do you just have a flakey internet connection?

@@ -0,0 +1,47 @@
module Bundler
class Retry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include motivation for this class as a class level comment.

@xaviershay
Copy link
Contributor

Oh I just read the linked PR, I see where this came from.

@definition.resolve_with_cache!
else
Bundler::Retry.new("source fetch", retry_times).attempts do
@definition.resolve_remotely!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a little surprised to see the retry handled at this level (wrapped around the entire resolution process) rather than at a lower level (like around individual network calls or calls out to git). I'm just wondering why you decided to go that way.

My concern is that this requires resolve_remotely! to be fully idempotent (or else bugs) and to have enough internal caching that it would avoid redoing work that completed successfully on a previous try. It's not clear to me whether that's the case right now (it looks like it could be, but there's a lot going on in there) and it would be really easy to accidentally break in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was more a proof of concept showing how I could utilize the code, we could push it lower level, or i could rip out this implementation just merge in the Retry class. The key is that there are several areas where we might want to retry code, and writing retry code by hand each time makes those implementations much less clear.

@schneems
Copy link
Contributor Author

Been a month, i realize priorities are towards speed for this release, but are there any additional thoughts or comments here? Is this PR being considered or should it be closed?

@indirect
Copy link
Member

As a general policy, I think we should retry all failed network requests at least once, and maybe twice, by default. adding --retry to increase the number of retries allowed also seems good.

@schneems, are you interested in expanding this to include retrying gem and git fetching, or is gemspecs as far as your interest goes?

On Wed, Sep 18, 2013 at 8:02 AM, Richard Schneeman
notifications@github.com wrote:

Been a month, i realize priorities are towards speed for this release, but are there any additional thoughts or comments here? Is this PR being considered or should it be closed?

Reply to this email directly or view it on GitHub:
#2601 (comment)

@schneems
Copy link
Contributor Author

Thanks for the reply. I would be happy to take a stab at retrying in those places.

@indirect
Copy link
Member

Awesome. Thanks! :D

@schneems
Copy link
Contributor Author

As of now the feature defaults to 3 attempts (the first plus two retries). To skip retries all together you can run with --retry 0. Any number you pass to --retry will be run one additional time. So if you run --retry 9 it will attempt to run it 10 times total (1 initial time, and 9 retries).

Added git retry functionality. As implemented it will retry all git commands. This is a pretty invasive change, but the cleanest way to implement the feature. For the gem fetching retry, is this a decent place for the retry functionality https://github.com/bundler/bundler/blob/master/lib/bundler/installer.rb#L107 ?

@indirect
Copy link
Member

can we maybe just whitelist git commands that hit the network? it seems silly to run git reset --hard ten times if it fails the first time...

@flyinprogrammer
Copy link

this addresses #2421

@indirect
Copy link
Member

If someone wants to rebase this, I am 👍 on merging.

This PR adds a general purpose Retry class that can be re-used where-ever retry code is needed!

It also allows you to call `bundle install --retry 3` which will attempt to connect to ruby gems 3 times before failing, and emit a warning message each time
@schneems
Copy link
Contributor Author

rebased, but we're still retrying on all git commands, haven't had time to work on some kind of whitelisting.

I also cleaned up some committed code while rebasing, using custom error classes makes the code much more readable IMHO.

@indirect
Copy link
Member

I'm down, then. Thanks!

indirect added a commit that referenced this pull request Sep 28, 2013
Retry fetch specs with `--retry`
@indirect indirect merged commit e82fde4 into rubygems:master Sep 28, 2013
@flyinprogrammer
Copy link

do we want to refactor this to use this new retry class?

https://github.com/bundler/bundler/blob/master/lib/bundler/fetcher.rb#L157-L192

@indirect
Copy link
Member

@flyinprogramer you're welcome to give it a shot, but the Fetcher should only retry on very specific exceptions — the retry class is just a generic retry thing.

@schneems
Copy link
Contributor Author

I would add an arg to the attempt method that takes an optional error
class and saves it to an @classes_to_rescue_from_exception, have it default
to Standard error if no values are given, then rescue from that instance
variable here:
https://github.com/bundler/bundler/blob/master/lib/bundler/retry.rb#L34-L40.

That way you could write something like

Bundler::Retry.new.attempts(MyCustomError, GitError) do
  # code to retry now
end

@indirect
Copy link
Member

Oh lols, the tests use stabby proc >:|

@schneems
Copy link
Contributor Author

Whoops was on auto pilot on that one. I'm at a wedding for the rest of the weekend :/


Sent from Mailbox for iPhone

On Sat, Sep 28, 2013 at 3:35 PM, André Arko notifications@github.com
wrote:

Oh lols, the tests use stabby proc >:

Reply to this email directly or view it on GitHub:
#2601 (comment)

@indirect
Copy link
Member

I fixed it. Have a good weekend! 🤘

On Sat, Sep 28, 2013 at 2:43 PM, Richard Schneeman
notifications@github.com wrote:

Whoops was on auto pilot on that one. I'm at a wedding for the rest of the weekend :/

Sent from Mailbox for iPhone
On Sat, Sep 28, 2013 at 3:35 PM, André Arko notifications@github.com
wrote:

Oh lols, the tests use stabby proc >:

Reply to this email directly or view it on GitHub:

#2601 (comment)

Reply to this email directly or view it on GitHub:
#2601 (comment)

@schneems
Copy link
Contributor Author

❤️ 💓 😍 ❤️

@xbeta
Copy link

xbeta commented Apr 10, 2014

+1 for this neat feature! when can we expect a PR merge?

@Who828
Copy link
Contributor

Who828 commented Apr 11, 2014

@xbeta the feature had already been shipped with Bundler 1.5,
http://bundler.io/v1.5/bundle_install.html#retry

Just update your Bundler to the latest version to use it :)

@xbeta
Copy link

xbeta commented Apr 11, 2014

@Who828 Cool! I guess I miss that part on the doc!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants