Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 3371cf1

Browse files
authored
fix(cli-integ): sporadic npm connection resets (#81)
We are [seeing](https://github.com/aws/aws-cdk-cli-testing/actions/runs/14354194579/job/40239880803?pr=80) some sporadic failures during installation of npm packages in tests: ```console 💻 cp -R /home/runner/work/aws-cdk-cli-testing/aws-cdk-cli-testing/resources/cdk-apps/app/* /tmp/cdk-integ-0uxqgf2j5kce 💻 node /home/runner/work/aws-cdk-cli-testing/aws-cdk-cli-testing/node_modules/npm/index.js install npm ERR! code ECONNRESET npm ERR! network aborted ``` Lets applya retry on recoverable errors like these.
1 parent a8d4f39 commit 3371cf1

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,27 @@ export async function installNpmPackages(fixture: TestFixture, packages: Record<
788788
devDependencies: packages,
789789
}, undefined, 2), { encoding: 'utf-8' });
790790

791-
// Now install that `package.json` using NPM7
792-
await fixture.shell(['node', require.resolve('npm'), 'install']);
791+
// we often ECONNRESET from NPM so lets retry. this might be because of high concurrency
792+
// which overwhelmes system resources.
793+
const timeoutMinutes = 10;
794+
const timeoutDate = new Date(Date.now() + timeoutMinutes * 60 * 1000)
795+
const retryAfterSeconds = 30;
796+
797+
while (true) {
798+
try {
799+
// Now install that `package.json` using NPM7
800+
await fixture.shell(['node', require.resolve('npm'), 'install']);
801+
break;
802+
} catch (e: any) {
803+
if (Date.now() < timeoutDate.getTime() && fixture.output.toString().includes('ECONNRESET' )) {
804+
fixture.log(`npm install failed due to ECONNRESET. Retrying in ${retryAfterSeconds} seconds...`);
805+
await sleep(retryAfterSeconds * 1000)
806+
continue;
807+
}
808+
throw e;
809+
}
810+
}
811+
793812
}
794813

795814
const ALREADY_BOOTSTRAPPED_IN_THIS_RUN = new Set();

0 commit comments

Comments
 (0)