A lease lost while the state root is opening is a fence, not a crash
The startup persist now sits behind the same gate as every other write; its LeaseLost ended serve() as an unhandled rejection. onLost has already run, so serve returns without reporting active. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f69e24eeff
commit
302e97b72d
1 changed files with 9 additions and 3 deletions
|
|
@ -778,9 +778,14 @@ export async function serve(rt) {
|
|||
stopWorker().finally(() => runtime.reportHealth?.("degraded"));
|
||||
};
|
||||
runtime.watch(onLost); // held() reports a loss through this the moment any gate sees it
|
||||
guard();
|
||||
await mkdir(path.join(args.stateRoot, "jobs"), { recursive: true });
|
||||
await persistSurfaces();
|
||||
try {
|
||||
guard();
|
||||
await mkdir(path.join(args.stateRoot, "jobs"), { recursive: true });
|
||||
await persistSurfaces();
|
||||
} catch (error) {
|
||||
if (error instanceof LeaseLost) return; // lost while opening the state root: onLost has run, and nothing is active
|
||||
throw error;
|
||||
}
|
||||
surfaceTimer = setInterval(() => {
|
||||
runtime.watch(onLost);
|
||||
if (lost) return;
|
||||
|
|
@ -788,6 +793,7 @@ export async function serve(rt) {
|
|||
if (!(error instanceof LeaseLost)) console.error(`persist failed: ${error?.name || "Error"}`);
|
||||
});
|
||||
}, 5000);
|
||||
if (lost) return;
|
||||
runtime.reportHealth?.("active");
|
||||
console.log("Vili holds the state root");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue