fix(history): hoisted busy_timeout before sqlite_master probe

The sqlite_master probe runs before any other statement and can take a
read lock or trigger WAL recovery, so under the same concurrent-startup
race fixed in #2421 it could throw SQLITE_BUSY before PRAGMA
busy_timeout ran. Install the busy handler immediately after opening
the Database, matching every other init path.

Fixes #2421
This commit is contained in:
roboomp
2026-06-14 07:11:42 +00:00
parent 03bead1eac
commit 7bebcf883e
@@ -84,10 +84,10 @@ export class HistoryStorage {
this.#db = new Database(dbPath);
const hasFts = this.#db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='history_fts'").get();
// Install the busy handler BEFORE any lock-taking statement. See #2421.
this.#db.run("PRAGMA busy_timeout = 5000");
const hasFts = this.#db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='history_fts'").get();
this.#db.run(`
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;