Skip to content

Commit 24dc26d

Browse files
committed
fix(server): stop the owner poll on shutdown and wait out the launcher probe
1 parent fa20a12 commit 24dc26d

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎apps/server/src/serverOwnership.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ export const acquireServerOwnership = Effect.fn("acquireServerOwnership")(functi
200200
}
201201
const db = new NodeSqlite.DatabaseSync(lockPath);
202202
try {
203-
db.exec("PRAGMA busy_timeout = 0; BEGIN EXCLUSIVE;");
203+
// An idle service launcher probes this lock for a moment; wait out that probe.
204+
db.exec("PRAGMA busy_timeout = 250; BEGIN EXCLUSIVE;");
204205
const identity = NodeFS.statSync(lockPath, { bigint: true });
205206
return {
206207
db,

‎apps/server/src/serviceLauncher.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ export class Launcher {
565565
this.#enqueue(async () => {
566566
// Let in-progress updates start replacements first; replacements observe the marker and own pre-activation tunnel cleanup.
567567
this.#stopping = true;
568+
// An exit-78 transition queued before this one may have started the owner poll.
569+
this.#clearTimer();
568570
const child = this.#child?.process;
569571
this.#child = null;
570572
if (child !== undefined) await terminateChild(child, signal);
@@ -852,7 +854,11 @@ export class Launcher {
852854
}
853855

854856
async #reclaimStateDir(): Promise<void> {
855-
if (this.#timer === undefined || this.#child !== null || this.#stopRequested) return;
857+
if (this.#stopRequested) {
858+
this.#clearTimer();
859+
return;
860+
}
861+
if (this.#timer === undefined || this.#child !== null) return;
856862
if (stateDirOwned(this.#baseDir)) return;
857863
this.#clearTimer();
858864
process.stderr.write("[service-launcher] The T3 home is free again. Starting the server.\n");

0 commit comments

Comments
 (0)