Skip to content

Make aspnetcore npm ci restore robust to transient failures - #7361

Merged
mmitche merged 1 commit into
dotnet:mainfrom
mmitche:dev/npm-ci-retry
Jun 25, 2026
Merged

mmitche merged 1 commit into
dotnet:mainfrom
mmitche:dev/npm-ci-retry

Conversation

@mmitche

@mmitche mmitche commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Makes the aspnetcore npm ci restore step resilient to transient npm ci failures that non-deterministically break the VMR build.

The Restore target in src/aspnetcore/eng/Npm.Workspace.nodeproj invokes npm ci directly. When npm ci exits non-zero for a transient reason, the whole multi-hour unified build fails and must be manually re-run. Observed manifestations:

  • ECONNRESET / "Invalid response body while trying to fetch ..." while pulling packages from the dotnet-public-npm feed. .npmrc already sets fetch-retries=5, but npm's built-in retry does not reliably recover from errors that occur while reading the response body — so a single body-read reset fails the command.
  • npm ci exiting with code 57005 (0xDEAD) — an abnormal Node/Windows exit with no network diagnostic.

Fix

Wrap npm ci in a small cross-platform node retry helper, src/aspnetcore/eng/scripts/npm/npm-ci-retry.mjs, and call it from the Restore target instead of invoking npm ci directly.

  • Retries up to 5 attempts with linear backoff (15s × attempt).
  • Retries on any non-zero exit, so it covers both the network (ECONNRESET) and abnormal-exit (0xDEAD) cases above.
  • npm ci is a clean install, so re-running between attempts is safe.
  • Node is already a build prerequisite and is used by the neighboring pack-workspace.mjs scripts, so no new dependency is introduced.

Expected impact

I analyzed every dotnet-unified-build run on main and release/* queued in the last 30 days (internal pipeline, definition 1330), across all result types, inspecting every attempt (final + all retried previousAttempts timelines) for an aspnetcore npm ci failure:

Denominator Builds npm-ci failures %
All builds (any result) 283 2 0.71%
Non-green only (failed + partiallySucceeded) 251 2 0.80%
Failed only 166 2 1.2%

The two covered builds:

  • 3007299 (release/11.0.1xx-preview6) — exit 1, ECONNRESET / "Invalid response body"
  • 2992464 (release/11.0.1xx-preview5) — exit 57005 (0xDEAD)

Notes:

  • Both failures occurred on the final attempt — neither was already absorbed by an existing leg retry, so this is net-new coverage.
  • Each occurrence is a full build failure requiring a manual rerun, so the per-incident cost is high even though the rate is modest.
  • The change is low risk: it only retries a clean npm ci and changes no package manifests.

Note on canonical location

This file is mirrored from dotnet/aspnetcore (eng/Npm.Workspace.nodeproj, eng/scripts/npm/). The durable fix should also land upstream so it survives code flow; this PR is raised against the VMR per request.

The 'npm ci' step in eng/Npm.Workspace.nodeproj fails non-deterministically
when a transient network error (e.g. ECONNRESET while reading the response
body) occurs against the npm registry. npm's built-in fetch-retries does not
reliably recover from body-read errors, so a single hiccup fails the build.

Wrap 'npm ci' in a node retry helper (eng/scripts/npm/npm-ci-retry.mjs) that
retries with backoff before failing.

Co-authored-by: Copilot <[email protected]>
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team June 24, 2026 21:17
@mmitche
mmitche marked this pull request as ready for review June 24, 2026 21:35
Copilot AI review requested due to automatic review settings June 24, 2026 21:35
@mmitche
mmitche requested a review from wtgodbe June 24, 2026 21:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves reliability of the VMR unified build by making the aspnetcore NPM restore step resilient to transient npm ci failures, avoiding full-build reruns caused by flaky network/Node exits.

Changes:

  • Add a cross-platform Node.js retry wrapper that runs npm ci up to 5 times with linear backoff.
  • Update the aspnetcore Restore MSBuild target to invoke the retry wrapper instead of calling npm ci directly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/aspnetcore/eng/scripts/npm/npm-ci-retry.mjs New retry wrapper script that runs npm ci with backoff and retries.
src/aspnetcore/eng/Npm.Workspace.nodeproj Switches the Restore target from npm ci to the new retry wrapper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mmitche
mmitche enabled auto-merge (squash) June 24, 2026 22:00
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team June 24, 2026 22:00
@akoeplinger

Copy link
Copy Markdown
Member

could we make an arcade RetryExec utility msbuild task instead for this? We have the same problem in other repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants