fix(process): stop cancelled Swift helper builds before removing their files

Cancelling the macOS process-ownership helper build left swiftc object files
in TMPDIR. Node's execFile sends SIGTERM on abort and rejects before the
child exits, and swift-driver runs each frontend job in its own process
group: on SIGTERM the driver exits while a job keeps writing, so REA removed
its root while objects were still being written outside and inside it.

Add an opt-in `stopSignal` to execFileOutput that stops the process with the
caller's signal on abort or timeout and settles only after it exits. Swift
helper builds stop swiftc with SIGINT, on which swift-driver stops its jobs
and deletes their objects, and point TMPDIR inside the root cleanup removes.

Fixes #1173

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-09 03:43:43 +00:00
co-authored by Claude Opus 5.5
parent 4fb2f3e6ed
commit c717204795
5 changed files with 231 additions and 10 deletions
+7 -1
View File
@@ -1,7 +1,8 @@
import { mkdtemp, rm, symlink } from "node:fs/promises";
import { mkdir, mkdtemp, rm, symlink } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { SWIFTC_INTERRUPT } from "../process/DarwinProcessRunTokenReader.js";
import { execFileOutput } from "../process/ExecFileOutput.js";
import { safeParseJson } from "../domain/safeJson.js";
import type { NativeUiHelper } from "./NativeUiObservation.js";
@@ -22,6 +23,9 @@ export const createNativeUiHelperRuntime = () => {
),
main,
);
// Keep swiftc's intermediate objects inside the removable root.
const compilerTemporary = join(root, "tmp");
await mkdir(compilerTemporary);
await execFileOutput(
"/usr/bin/xcrun",
[
@@ -41,6 +45,8 @@ export const createNativeUiHelperRuntime = () => {
{
timeout: 60_000,
maxBuffer: 1024 * 1024,
stopSignal: SWIFTC_INTERRUPT,
env: { ...process.env, TMPDIR: compilerTemporary },
...(signal === undefined ? {} : { signal }),
},
);