mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 14:52:09 +03:00
getDbInstance()'s probe-then-reopen pattern (written for per-open-handle drivers like better-sqlite3/node:sqlite) was calling .close() on a throwaway probe connection before opening the "real" connection right after. For sql.js, openSqliteDatabase()'s fallback path always returns the SAME module-global cached singleton for a given filePath, so closing "the probe" closed the ONLY connection that file would ever get until process restart — every subsequent query threw sql.js's raw "Database closed" string, matching the reported crash-loop on every boot once storage.sqlite already exists and both sync drivers are unavailable. Adds closeProbeIfSafe() (src/lib/db/core.ts) and uses it at every probe-close site in getDbInstance()/captureCriticalDbState() — it skips the close for sql.js-backed adapters and lets the same live adapter flow through, while still closing real per-handle drivers normally. Also makes sqljsAdapter.ts's gracefulClose() remove its 3 process-level listeners (beforeExit/SIGINT/SIGTERM) so a closed adapter's closure (raw sql.js Database + buffers) can actually be garbage collected instead of being pinned forever — addresses the compounding-OOM sub-finding as a consequence of the same defect. Regression test: tests/unit/db-sqljs-close-poison-7494.test.ts