mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
fix(process): preserve Darwin snapshot and cleanup failures (#12100)
* fix(process): preserve Darwin opening snapshot failures * fix(process): retain the exact Darwin helper cleanup owner Transfer the failed helper-root capability across repeated prepare failures. Reuse that same owner for retirement and reader close so stale cleanup cannot remove a replacement helper. Co-authored-by: Anandumv <anandumv@gmail.com> Co-authored-by: nextjohnp7 <nextjohnp7@gmail.com> * test(process): isolate retained cleanup and compiler acknowledgements --------- Co-authored-by: Anandumv <anandumv@gmail.com> Co-authored-by: nextjohnp7 <nextjohnp7@gmail.com>
This commit is contained in:
6 files changed
+216
-53
No files matched your search
@@ -406,6 +406,7 @@ const compilerInspectionError = (
|
||||
/** One allocated helper root, including its shared finalization and live cleanup status. */
|
||||
interface ProcessReaderRoot {
|
||||
readonly path: string;
|
||||
close(): Promise<void>;
|
||||
cleanupPromise?: Promise<void> | undefined;
|
||||
/** Reported by every removal failure until a retry removes the root. */
|
||||
cleanupRelease?: AnalysisCleanupRelease | undefined;
|
||||
@@ -533,8 +534,7 @@ export const createDarwinProcessRunTokenReader = (
|
||||
const cleanupAtExit = () => {
|
||||
if (root !== undefined) removeHelperRootAtExit(root.path);
|
||||
};
|
||||
const cleanupRoot = (target = root): Promise<void> => {
|
||||
if (target === undefined) return Promise.resolve();
|
||||
const cleanupRoot = (target: ProcessReaderRoot): Promise<void> => {
|
||||
target.cleanupPromise ??= Promise.resolve()
|
||||
.then(async () => {
|
||||
try {
|
||||
@@ -567,6 +567,33 @@ export const createDarwinProcessRunTokenReader = (
|
||||
});
|
||||
return target.cleanupPromise;
|
||||
};
|
||||
const cleanupFailedCompilationRoot = async (
|
||||
target: ProcessReaderRoot,
|
||||
primaryFailure?: ProcessReaderCompilation["primaryFailure"],
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await target.close();
|
||||
} catch (cleanup: unknown) {
|
||||
if (!(cleanup instanceof ProviderCleanupError)) throw cleanup;
|
||||
const cause =
|
||||
primaryFailure === undefined ? cleanup : primaryFailure.cause;
|
||||
const primary =
|
||||
cause instanceof DarwinProcessOwnershipInspectionError
|
||||
? cause
|
||||
: new DarwinProcessOwnershipInspectionError(
|
||||
primaryFailure === undefined
|
||||
? "Darwin process ownership helper root cleanup retry failed"
|
||||
: "Darwin process ownership helper preparation failed",
|
||||
{
|
||||
cause,
|
||||
...(cause instanceof ProcessOwnershipInspectionCancelled
|
||||
? { cancellation: { reason: cause.reason } }
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
throw primary.withCleanupFailure(cleanup, target);
|
||||
}
|
||||
};
|
||||
const runCompilation = async (
|
||||
operation: ProcessReaderCompilation,
|
||||
): Promise<string> => {
|
||||
@@ -592,10 +619,12 @@ export const createDarwinProcessRunTokenReader = (
|
||||
executable = cached.executable;
|
||||
return cached.executable;
|
||||
}
|
||||
operationRoot = {
|
||||
const allocatedRoot: ProcessReaderRoot = {
|
||||
path: await mkdtemp(join(tmpdir(), "rea-process-token-")),
|
||||
close: () => cleanupRoot(allocatedRoot),
|
||||
};
|
||||
root = operationRoot;
|
||||
operationRoot = allocatedRoot;
|
||||
root = allocatedRoot;
|
||||
process.once("exit", cleanupAtExit);
|
||||
exitCleanupInstalled = true;
|
||||
if (signal.aborted || closed)
|
||||
@@ -654,26 +683,10 @@ export const createDarwinProcessRunTokenReader = (
|
||||
// The extra pipe keeps settlement pending for Swift frontend writers
|
||||
// that inherit it after the driver and its standard streams close.
|
||||
// It cannot establish completion of a child that did not inherit it.
|
||||
try {
|
||||
await cleanupRoot(operationRoot);
|
||||
} catch (cleanup: unknown) {
|
||||
if (!(cleanup instanceof ProviderCleanupError)) throw cleanup;
|
||||
const primary =
|
||||
cause instanceof DarwinProcessOwnershipInspectionError
|
||||
? cause
|
||||
: new DarwinProcessOwnershipInspectionError(
|
||||
"Darwin process ownership helper preparation failed",
|
||||
{
|
||||
cause,
|
||||
...(cause instanceof ProcessOwnershipInspectionCancelled
|
||||
? { cancellation: { reason: cause.reason } }
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
throw primary.withCleanupFailure(cleanup, {
|
||||
close: () => cleanupRoot(operationRoot),
|
||||
});
|
||||
}
|
||||
await cleanupFailedCompilationRoot(
|
||||
operationRoot,
|
||||
operation.primaryFailure,
|
||||
);
|
||||
}
|
||||
throw cause;
|
||||
}
|
||||
@@ -706,7 +719,7 @@ export const createDarwinProcessRunTokenReader = (
|
||||
assertProcessOwnershipInspectionActive(signal);
|
||||
if (executable !== undefined) return executable;
|
||||
if (compilation === undefined && root !== undefined) {
|
||||
await cleanupRoot();
|
||||
await cleanupFailedCompilationRoot(root);
|
||||
continue;
|
||||
}
|
||||
let operation = compilation;
|
||||
@@ -920,7 +933,7 @@ export const createDarwinProcessRunTokenReader = (
|
||||
// Each owner keeps its own failed cleanup for the next close attempt;
|
||||
// a failure of both stays incomplete until both owners recover.
|
||||
const [rootCleanup, cacheCleanup] = await Promise.allSettled([
|
||||
cleanupRoot(),
|
||||
root?.close(),
|
||||
helperCache?.close(),
|
||||
]);
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user