Skip to content

Commit 001b2c4

Browse files
t3dotggclaude
andcommitted
fix(server): hold the update lock through a queued restart handoff
With --no-block the restart fiber completes while the old process is still shutting down; the unconditional ensuring released the in-flight lock at that point, letting a second update rewrite the unit mid-teardown. Release the lock only on the failure path, after the rollback has restored the previous unit. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 513de4c commit 001b2c4

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎apps/server/src/cloud/selfUpdate.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,14 @@ it.layer(NodeServices.layer)("ServerSelfUpdate.update", (it) => {
550550
assert.lengthOf(context.spawns, 0);
551551
// systemd replaces the process; the server must not exit itself.
552552
assert.equal(context.exitCount(), 0);
553+
554+
// The queued restart returns while this process is still shutting
555+
// down; the lock must stay held so a second update cannot rewrite the
556+
// unit mid-teardown.
557+
const concurrentError = yield* context.service
558+
.update({ targetVersion: "0.0.30" })
559+
.pipe(Effect.flip);
560+
assert.include(concurrentError.reason, "already in progress");
553561
}).pipe(Effect.provide(TestClock.layer())),
554562
);
555563

‎apps/server/src/cloud/selfUpdate.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,13 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* (option
394394
Effect.catch((error) =>
395395
Effect.logError("Server self-update could not restart the boot service.").pipe(
396396
Effect.annotateLogs({ targetVersion, error: error.reason }),
397+
// Permit a retry only after the failed handoff was rolled
398+
// back. A queued restart returns while this process is still
399+
// shutting down; releasing the lock then would let a second
400+
// update rewrite the unit mid-teardown.
401+
Effect.andThen(Ref.set(inFlight, false)),
397402
),
398403
),
399-
Effect.ensuring(Ref.set(inFlight, false)),
400404
),
401405
);
402406
} else {

0 commit comments

Comments
 (0)