Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a slow database write no longer freezes the server #35728

Mergedtnfssc(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/35728/headmerged by juliusmarminge View on GitHub

Showing 7 changed files with 32 additions and 105 deletions (loading 5).

x
0 of 7 viewed, 7 left
31 additions and 31 deletionsapps/server/src/orchestration-v2/FoundationPersistence.test.tsModified
View file
@@ -1,4 +1,4 @@
-import * as NodeSqlite from "node:sqlite";
+import type * as NodeWorkerThreads from "node:worker_threads";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it } from "@effect/vitest";
import {
@@ -73,6 +73,29 @@
import * as ProviderRuntimeRecovery from "./ProviderRuntimeRecoveryService.ts";
import * as TurnItemPositionStore from "./TurnItemPositionStore.ts";
​
+const workerStatements = vi.hoisted(
+ (): Array<{ readonly readOnly: boolean; readonly sql: string }> => [],
+);
+​
+vi.mock("node:worker_threads", async (importOriginal) => {
+ const actual = await importOriginal<typeof NodeWorkerThreads>();
+ class RecordedWorker extends actual.Worker {
+ readonly #readOnly: boolean;
+ constructor(...args: ConstructorParameters<typeof actual.Worker>) {
+ super(...args);
+ this.#readOnly = args[1]?.workerData?.readOnly === true;
+ }
+ override postMessage(...args: Parameters<NodeWorkerThreads.Worker["postMessage"]>) {
+ const [message] = args;
+ if (typeof message === "object" && message !== null && typeof message.sql === "string") {
+ workerStatements.push({ readOnly: this.#readOnly, sql: message.sql });
+ }
+ return super.postMessage(...args);
+ }
+ }