mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
When better-sqlite3/node:sqlite are unavailable and the sql.js WASM fallback OOMs while probing storage.sqlite, getDbInstance() rethrew an identical 'Out of memory while probing' error on every call, forever — unlike the generic-corruption probe-failure path (#6632), which correctly caps at 3 attempts via the restore-count cycle breaker. Because the OOM path never renames the file away (intentional — OOM is not corruption), the existing cap is structurally unreachable for this branch, so every independent background poller (BATCH, ProviderLimitsSync, HealthCheck, ModelSync) kept re-triggering the same failure with no terminal diagnostic, hanging the app forever. Adds an independent __omnirouteDbOomFailureCount cycle-breaker mirroring the existing threshold of 3, throwing a distinct terminal 'Aborting startup' diagnostic after repeated OOM failures instead of looping. Does not touch the rename/backup safety mechanism. Reported-by: xHmeyer, mostafa-binesh
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
test("getDbInstance() caps the probe-failed/restore cycle at 3 attempts (#6835)", async () => {
|
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-6835-"));
|
|
process.env.DATA_DIR = tmpDir;
|
|
const sqliteFile = path.join(tmpDir, "storage.sqlite");
|
|
const backupFile = `${sqliteFile}.probe-failed-1000000000000`;
|
|
fs.writeFileSync(backupFile, Buffer.from("not a real sqlite file, always fails to open"));
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const errors: string[] = [];
|
|
for (let i = 0; i < 6; i++) {
|
|
try {
|
|
core.getDbInstance();
|
|
errors.push("(no error)");
|
|
break;
|
|
} catch (err: unknown) {
|
|
errors.push(err instanceof Error ? err.message : String(err));
|
|
}
|
|
}
|
|
const abortIndex = errors.findIndex((e) => e.includes("Aborting startup"));
|
|
assert.notEqual(abortIndex, -1, "Expected the cap to trip; got: " + errors.join(" | "));
|
|
assert.ok(abortIndex <= 4, "Expected cap by call #4; took until #" + abortIndex);
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|