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:
co-authored by
Claude Opus 5.5
parent
4fb2f3e6ed
commit
c717204795
@@ -1,4 +1,4 @@
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
@@ -65,6 +65,13 @@ const sourceFiles = [
|
||||
),
|
||||
];
|
||||
|
||||
/**
|
||||
* swift-driver runs each frontend job in its own process group. On SIGINT it
|
||||
* stops those jobs and deletes their objects before exiting; on SIGTERM it
|
||||
* exits while a job can still write objects under TMPDIR.
|
||||
*/
|
||||
export const SWIFTC_INTERRUPT = "SIGINT";
|
||||
|
||||
/** The native Darwin process-ownership reader could not be prepared. */
|
||||
export class DarwinProcessOwnershipInspectionError extends Error {
|
||||
constructor(message: string, options?: ErrorOptions) {
|
||||
@@ -149,7 +156,14 @@ export const createDarwinProcessRunTokenReader = (
|
||||
exitCleanupInstalled = true;
|
||||
if (signal.aborted || closed) throw abortReason(signal);
|
||||
const output = join(operationRoot, "reader");
|
||||
const compilerEnvironment = { ...process.env };
|
||||
// swiftc keeps intermediate objects under TMPDIR, so keep them inside
|
||||
// the root that cleanup removes.
|
||||
const compilerTemporary = join(operationRoot, "tmp");
|
||||
await mkdir(compilerTemporary);
|
||||
const compilerEnvironment: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
TMPDIR: compilerTemporary,
|
||||
};
|
||||
// Use Swift's reusable default cache for REA's internal helper compilation.
|
||||
delete compilerEnvironment.CLANG_MODULE_CACHE_PATH;
|
||||
try {
|
||||
@@ -160,6 +174,7 @@ export const createDarwinProcessRunTokenReader = (
|
||||
timeout: 60_000,
|
||||
maxBuffer: 1024 * 1024,
|
||||
signal,
|
||||
stopSignal: SWIFTC_INTERRUPT,
|
||||
env: compilerEnvironment,
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user