Skip to content

Commit bc36629

Browse files
committed
fix: add retry logic for npm install to handle transient registry failures
Add retry logic with exponential backoff (5s, 10s, 20s) to handle transient NPM registry failures like 503 Service Unavailable errors. This prevents build failures when npmjs.org has temporary outages, which can happen during CI runs. Features: - 3 retry attempts with exponential backoff - Detailed logging of retry attempts - Only fails after all retries exhausted Fixes the Production Readiness CI failure seen at: https://github.com/pulseengine/rules_wasm_component/actions/runs/19322218044
1 parent 4fb1acf commit bc36629

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

toolchains/jco_toolchain.bzl

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,43 @@ def _setup_downloaded_jco_tools(repository_ctx, platform, jco_version, node_vers
200200

201201
print("JCO dependencies configured")
202202

203-
# Actually install the packages using npm
204-
npm_install_result = repository_ctx.execute([
205-
str(npm_binary),
206-
"install",
207-
"--global-style",
208-
"--no-package-lock",
209-
] + install_packages, environment = npm_env, working_directory = "jco_workspace")
203+
# Install packages with retry logic for transient registry failures
204+
max_retries = 3
205+
retry_delay_seconds = 5
206+
npm_install_result = None
207+
208+
for attempt in range(1, max_retries + 1):
209+
if attempt > 1:
210+
print("Retrying npm install (attempt {}/{}) after {}s delay...".format(
211+
attempt, max_retries, retry_delay_seconds
212+
))
213+
# Simple delay using execute with sleep
214+
repository_ctx.execute(["sleep", str(retry_delay_seconds)])
215+
retry_delay_seconds *= 2 # Exponential backoff
216+
217+
npm_install_result = repository_ctx.execute([
218+
str(npm_binary),
219+
"install",
220+
"--global-style",
221+
"--no-package-lock",
222+
] + install_packages, environment = npm_env, working_directory = "jco_workspace")
223+
224+
if npm_install_result.return_code == 0:
225+
break
226+
227+
print("npm install attempt {} failed (return code: {})".format(
228+
attempt, npm_install_result.return_code
229+
))
230+
if attempt < max_retries:
231+
print("STDERR:", npm_install_result.stderr)
210232

211233
if npm_install_result.return_code != 0:
212-
print("ERROR: npm install failed:")
234+
print("ERROR: npm install failed after {} attempts:".format(max_retries))
213235
print("STDOUT:", npm_install_result.stdout)
214236
print("STDERR:", npm_install_result.stderr)
215-
fail("Failed to install jco dependencies: {}".format(npm_install_result.stderr))
237+
fail("Failed to install jco dependencies after {} retries: {}".format(
238+
max_retries, npm_install_result.stderr
239+
))
216240

217241
print("JCO installation completed successfully")
218242

0 commit comments

Comments
 (0)