Apply BUNDLE_RETRY to lazy gemspec downloads - #9868
Open
IslamElsayed wants to merge 1 commit into
Open
Conversation
Resolving through the full-index API lazily downloads individual
gemspecs from /quick/Marshal.4.8/*.gemspec.rz. `Fetcher#fetch_spec` made
that request bare:
Bundler.safe_load_marshal Bundler.rubygems.inflate(downloader.fetch(uri).body)
while `specs_with_retry`, in the same class, wraps its network call in
`Bundler::Retry`. So a single transient failure — a read timeout, say —
aborted the whole resolution, no matter what BUNDLE_RETRY was set to.
That is most painful without a lockfile, where a resolve can fetch a
great many gemspecs one at a time and any one of them can end it.
Wrap the download in the same `Bundler::Retry.new("fetcher", FAIL_ERRORS)`
the index path already uses. FAIL_ERRORS is what keeps this from retrying
things that will not change, such as authentication failures.
Only the download branch is wrapped. The file:// and cached-gemspec
branches do no network I/O, so retrying them would just repeat a local
failure.
Closes ruby#9817
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9817.
What was the end-user or developer problem that led to this PR?
Resolving through the full-index API lazily downloads individual gemspecs from
/quick/Marshal.4.8/*.gemspec.rz. One transient failure on any of those — a read timeout, a reset connection — aborts the whole resolution, no matter whatBUNDLE_RETRYis set to.It bites hardest without a lockfile, where a resolve can fetch a great many gemspecs one at a time, so the chance that at least one hits a blip grows with the size of the dependency set. The reporter saw it as repeated production CI failures.
What is your fix for the problem, implemented in this PR?
Fetcher#fetch_specmade the request bare:while
specs_with_retry, twenty lines below in the same class, wraps its network call:So the retry machinery and its exclusion list already exist and are already tuned —
FAIL_ERRORSis there precisely to stop auth failures and other non-transient responses from being retried. The lazy per-gemspec path simply never opted in. This wraps that download in the sameBundler::Retry.new("fetcher", FAIL_ERRORS), so both network paths throughFetchernow behave the same way.Only the download branch is wrapped. The
file://and cached-gemspec branches do no network I/O, so retrying them would only repeat a local failure — and a corrupt cached gemspec should surface immediately rather than after N attempts.Alternative considered: retrying inside
Downloader#fetch, which is where the network exceptions are classified. I didn't, becauseDownloaderis shared by every fetcher path — including ones already wrapped inBundler::Retry— and retrying there would multiply attempts for those callers rather than fix the one that is missing them.Make sure the following tasks are checked
Two cases in
spec/bundler/fetcher_spec.rb, following the existing double-based style there:fetch_specreturns the spec. This fails onmaster— the error propagates on the first attempt.FAIL_ERRORSmember (AuthenticationRequiredError) is raised on the first attempt and not retried. This passes either way by design; it guards against the fix over-retrying things it shouldn't.Verified green:
spec/bundler/fetcher_spec.rb(25 examples), plusspec/bundler/fetcher/,remote_specification_spec.rb,endpoint_specification_spec.rbandretry_spec.rbtogether (145 examples, 2 pre-existing pending).bin/rake rubocopreports no offenses across 852 files.Disclosure
Written with AI assistance (Claude). I can explain every line, and the behaviour was verified by running the tests rather than inferred.