fix(process): retain ownership after incomplete cleanup

This commit is contained in:
morluto
2026-10-09 02:37:47 +08:00
parent be783efaba
commit e2fc2493b6
2 changed files with 31 additions and 9 deletions
+18 -4
View File
@@ -299,11 +299,14 @@ export class ProviderProcessSupervisor {
);
}
/** Stop an owned process once; concurrent callers share the same escalation. */
/** Share each stop attempt; incomplete cleanup retains ownership and permits retry. */
stop(
options: ProviderProcessStopOptions = {},
): Promise<ProviderProcessStopResult> {
this.#stopPromise ??= this.#stop(options);
this.#stopPromise ??= this.#stop(options).then((result) => {
if (result.status === "incomplete") this.#stopPromise = undefined;
return result;
});
return this.#stopPromise;
}
@@ -320,6 +323,19 @@ export class ProviderProcessSupervisor {
async #stop(
options: ProviderProcessStopOptions,
): Promise<ProviderProcessStopResult> {
let completed = false;
try {
const result = await this.#stopWithin(options);
completed = result.status !== "incomplete";
return result;
} finally {
if (completed) this.dispose();
}
}
async #stopWithin(
options: ProviderProcessStopOptions,
): Promise<ProviderProcessStopResult> {
try {
if (!this.launch.ownsProcessLifetime) return { status: "not-owned" };
@@ -366,8 +382,6 @@ export class ProviderProcessSupervisor {
? cause.message
: "owned provider process cleanup failed",
};
} finally {
this.dispose();
}
}