Skip to content

Commit 3b9bd77

Browse files
committed
build: update _exec to handle timeouts gracefully when waitForMatch does not match within 60 seconds.
Previously, if `waitForMatch` failed to find a match, the CI process could hang indefinitely. This commit updates the method to ensure it fails after a 60-second timeout, preventing such blocks. Example: https://github.com/angular/angular-cli/actions/runs/12709516529/job/35428835418?pr=29318 (cherry picked from commit a67825e)
1 parent 940ce56 commit 3b9bd77

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/legacy-cli/e2e/utils/process.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
7777
// Create the error here so the stack shows who called this function.
7878
const error = new Error();
7979

80-
return new Promise<ProcessOutput>((resolve, reject) => {
80+
const processPromise = new Promise<ProcessOutput>((resolve, reject) => {
8181
let stdout = '';
8282
let stderr = '';
8383
let matched = false;
@@ -158,6 +158,25 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
158158
error.message = err.toString();
159159
return Promise.reject(error);
160160
});
161+
162+
if (!options.waitForMatch) {
163+
return processPromise;
164+
}
165+
166+
let timeout: NodeJS.Timeout | undefined;
167+
const timeoutPromise: Promise<never> = new Promise((_resolve, reject) => {
168+
// Wait for 60 seconds and timeout.
169+
const duration = 60_000;
170+
timeout = setTimeout(() => {
171+
reject(
172+
new Error(`Waiting for ${options.waitForMatch} timed out (timeout: ${duration}msec)...`),
173+
);
174+
}, duration);
175+
});
176+
177+
return Promise.race([timeoutPromise, processPromise]).finally(
178+
() => timeout && clearTimeout(timeout),
179+
);
161180
}
162181

163182
export function extractNpmEnv() {

0 commit comments

Comments
 (0)