Skip to content

Commit

Permalink
Add retry to bundle install for some errors (#21803)
Browse files Browse the repository at this point in the history
Add retry to bundle install for some errors
  • Loading branch information
KevinFairise2 authored Jan 4, 2024
1 parent 6842031 commit 1f3aa6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
20 changes: 18 additions & 2 deletions tasks/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def omnibus_run_task(
ctx.run(cmd.format(**args), env=env)


def bundle_install_omnibus(ctx, gem_path=None, env=None):
def bundle_install_omnibus(ctx, gem_path=None, env=None, max_try=2):
with ctx.cd("omnibus"):
# make sure bundle install starts from a clean state
try:
Expand All @@ -665,7 +665,22 @@ def bundle_install_omnibus(ctx, gem_path=None, env=None):
cmd = "bundle install"
if gem_path:
cmd += f" --path {gem_path}"
ctx.run(cmd, env=env)

for trial in range(max_try):
res = ctx.run(cmd, env=env, warn=True)
if res.ok:
return
if not should_retry_bundle_install(res):
return
print(f"Retrying bundle install, attempt {trial + 1}/{max_try}")


def should_retry_bundle_install(res):
# We sometimes get a Net::HTTPNotFound error when fetching the
# license-scout gem. This is a transient error, so we retry the bundle install
if "Net::HTTPNotFound:" in res.stderr:
return True
return False


# hardened-runtime needs to be set to False to build on MacOS < 10.13.6, as the -o runtime option is not supported.
Expand Down Expand Up @@ -698,6 +713,7 @@ def omnibus_build(
"""
Build the Agent packages with Omnibus Installer.
"""

flavor = AgentFlavor[flavor]
if not skip_deps:
with timed(quiet=True) as deps_elapsed:
Expand Down
15 changes: 1 addition & 14 deletions tasks/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from invoke import task

from .agent import bundle_install_omnibus
from .build_tags import filter_incompatible_tags, get_build_tags, get_default_build_tags
from .go import deps
from .utils import REPO_PATH, bin_name, get_build_flags, get_version, load_release_versions, timed
Expand Down Expand Up @@ -120,20 +121,6 @@ def omnibus_run_task(ctx, task, target_project, base_dir, env, omnibus_s3_cache=
ctx.run(cmd.format(**args), env=env)


def bundle_install_omnibus(ctx, gem_path=None, env=None):
with ctx.cd("omnibus"):
# make sure bundle install starts from a clean state
try:
os.remove("Gemfile.lock")
except Exception:
pass

cmd = "bundle install"
if gem_path:
cmd += f" --path {gem_path}"
ctx.run(cmd, env=env)


# hardened-runtime needs to be set to False to build on MacOS < 10.13.6, as the -o runtime option is not supported.
@task(
help={
Expand Down

0 comments on commit 1f3aa6a

Please sign in to comment.