Skip to content

Commit c24d42c

Browse files
committed
fix(apple): keep cancellation typed when the final toolchain probe fails
The guard fold left one gap: a request that aborts while the last probe is in flight and then fails with a non-timeout error has no next attempt whose guard could see the abort, so the catch classified it as an unreadable toolchain. The catch checks the signal again before classifying, as it did before the fold.
1 parent b6611b6 commit c24d42c

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎packages/platform-apple/src/runner/__tests__/runner-cache-metadata.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,28 @@ describe('toolchain probe budget', () => {
338338
assert.equal(runCmdSync.mock.calls.length, 1);
339339
});
340340

341+
test('a non-timeout error that also cancels the request on the last probe surfaces cancellation, not an unavailable toolchain', () => {
342+
const request = new AbortController();
343+
runCmdSync.mockImplementation((command: string, args: string[]) => {
344+
// The final probe: abort the request and fail with a plain command
345+
// error, not the exec layer's structured timeout -- there is no next
346+
// attempt left to catch the cancellation, so the catch here must.
347+
if (command === 'xcrun' && args.includes('--show-sdk-build-version')) {
348+
request.abort();
349+
throw new AppError('COMMAND_FAILED', 'xcrun: unexpected error', {});
350+
}
351+
return appleToolchainProbeResult(command, args);
352+
});
353+
runCmdSync.mockClear();
354+
355+
assert.throws(
356+
() =>
357+
resolveExpectedRunnerCacheMetadata(IOS_SIMULATOR, undefined, { signal: request.signal }),
358+
(error: unknown) => isRequestCanceledError(error),
359+
);
360+
assert.equal(runCmdSync.mock.calls.length, 3);
361+
});
362+
341363
test('an already-canceled request runs no toolchain probe at all, cold or with the fingerprint cache warm', () => {
342364
installFakeToolchainClock();
343365
runCmdSync.mockClear();

‎packages/platform-apple/src/runner/runner-cache-metadata.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ function runToolchainProbe(
361361
} catch (error) {
362362
// A canceled request and a spent budget are the caller's own errors to
363363
// see, not an unreadable toolchain: only what's left becomes a probe
364-
// failure.
364+
// failure. Checked again here (not just in attemptToolchainProbe) because
365+
// the request can abort while this exec is in flight, after its own guard
366+
// already passed -- including on the last probe, where there is no next
367+
// attempt left to catch it.
368+
clock.throwIfCanceled();
365369
if (isRequestCanceledError(error) || isRunnerPhaseBudgetExhaustedError(error)) throw error;
366370
return probeFailure(probe, 'probe_error', error instanceof Error ? error.message : `${error}`);
367371
}

0 commit comments

Comments
 (0)