Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): report a deleted or replaced ownership lock #21886

MergedScottN-PV(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/21886/headmerged by maria-rcks View on GitHub

Showing 2 changed files with 140 additions and 5 deletions.

x
0 of 2 viewed, 2 left
49 additions and 5 deletionsapps/server/src/serverOwnership.tsModified
View file
@@ -44,7 +44,7 @@
override readonly [Runtime.errorExitCode] = SERVER_EXIT_CODE_STATE_DIR_OWNED;
​
override get message(): string {
- return `A T3 Code server already owns ${this.stateDir}. Stop that server, or use a separate T3 home and pair with it, then retry. No server was stopped.`;
+ return `A T3 Code server already owns ${this.stateDir}. Stop that server, or use a separate T3 home and pair with it, then retry. No server was stopped. server-owner.sqlite is the ownership lock; do not delete it while a server is running.`;
​
@@ -188,25 +188,36 @@
const ownerId = yield* crypto
.randomUUIDv4()
.pipe(Effect.mapError((cause) => new ServerOwnershipError({ stateDir, cause })));
- yield* Effect.acquireRelease(
+ const lockPath = NodePath.join(stateDir, "server-owner.sqlite");
+ const lock = yield* Effect.acquireRelease(
Effect.try({
try: () => {
NodeFS.mkdirSync(stateDir, { recursive: true });
- const db = new NodeSqlite.DatabaseSync(NodePath.join(stateDir, "server-owner.sqlite"));
+ let before = NodeFS.statSync(lockPath, { bigint: true, throwIfNoEntry: false });
+ if (before === undefined) {
+ NodeFS.closeSync(NodeFS.openSync(lockPath, "a", 0o644));
+ before = NodeFS.statSync(lockPath, { bigint: true });
+ }
+ const db = new NodeSqlite.DatabaseSync(lockPath);
try {
db.exec("PRAGMA busy_timeout = 0; BEGIN EXCLUSIVE;");
+ const identity = NodeFS.statSync(lockPath, { bigint: true });