Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): SQLite temp files no longer block the event loop #24194

Mergedonly21mil(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/24194/headmerged by maria-rcks View on GitHub

Showing 2 changed files with 48 additions and 0 deletions.

x
0 of 2 viewed, 2 left
45 additions and 0 deletionsapps/server/src/persistence/Sqlite.test.tsModified
View file
@@ -5,12 +5,57 @@
​
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it } from "@effect/vitest";
+import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as SqlClient from "effect/sql/SqlClient";
​
import * as SqlitePersistence from "./Sqlite.ts";
​
+// Linux names an open, already-deleted file "<path> (deleted)" in /proc/self/fd.
+// SQLite names its temp files "etilqs_*" and, without TMPDIR, puts them in
+// /var/tmp while os.tmpdir() is /tmp, so match the name, not the directory.
+const openDeletedTempFiles = () =>
+ NodeFS.readdirSync("/proc/self/fd").flatMap((fd) => {
+ try {
+ const target = NodeFS.readlinkSync(`/proc/self/fd/${fd}`);
+ return target.includes("/etilqs_") && target.endsWith(" (deleted)") ? [target] : [];
+ } catch {
+ return [];
+ }
+ });
+​
+it.effect.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
+ "keeps a write transaction's statement journal off the temp directory",
+ () => {
+ const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-sqlite-temp-"));
+ const persistence = SqlitePersistence.layerFromPath(
+ NodePath.join(tempDir, "state.sqlite"),