Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): enforce one owner per state directory #8960

Closedmaxibotstef(GitHub profile, opens in a new tab)wants to merge 11 commits intomain fromrefs/pull/8960/headopened View on GitHub

Showing 3 changed files with 31 additions and 2 deletions (loading 2).

x
0 of 3 viewed, 3 left
31 additions and 2 deletionsapps/server/src/server.tsModified
View file
@@ -56,6 +56,7 @@
import * as EnvironmentTheme from "./environmentTheme.ts";
import * as Keybindings from "./keybindings.ts";
import * as ServerRuntimeStartup from "./serverRuntimeStartup.ts";
+import * as ServerSingleton from "./serverSingleton.ts";
import { OrchestrationReactorLive } from "./orchestration/Layers/OrchestrationReactor.ts";
import { RuntimeReceiptBusLive } from "./orchestration/Layers/RuntimeReceiptBus.ts";
import { ProviderRuntimeIngestionLive } from "./orchestration/Layers/ProviderRuntimeIngestion.ts";
@@ -186,6 +187,21 @@
}),
​
+/**
+ * Claims the data directory before anything binds a port or opens the database.
+ *
+ * Provided once into `HttpServerLive`, which is then provided into the runtime
+ * services. That dependency chain makes the ordering structural: claim the state
+ * directory, bind HTTP, then open persistence/provider state. A second server
+ * cannot reach either protected phase while another holds the directory.
+ */
+const ServerSingletonLive = Layer.effectDiscard(
+ Effect.gen(function* () {
+ const config = yield* ServerConfig.ServerConfig;
+ yield* ServerSingleton.acquireServerSingleton(config.stateDir);
+ }),
+);
+​
const HttpServerLive = Layer.unwrap(
Effect.gen(function* () {