email: set busy_timeout on the email db to ride out concurrent writers
The API and email sidecar both open emails.db; without a busy timeout a write overlap (resync, or the thread_id backfill) throws "database is locked" and 500s a request. Wait up to 5s for the other writer instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -133,6 +133,9 @@ function fallbackThreadId(row: { id: string; subject: unknown; from_address: unk
|
||||
export function openEmailDb(email: string): Database {
|
||||
const dbPath = join(DATA_PATH, email, 'emails.db');
|
||||
const db = new Database(dbPath, { create: true });
|
||||
// The API and the email sidecar both open this file; wait out a concurrent writer (e.g. a resync
|
||||
// or the one-time thread_id backfill) instead of failing immediately with "database is locked".
|
||||
db.exec('PRAGMA busy_timeout = 5000');
|
||||
db.exec('PRAGMA journal_mode = DELETE');
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
db.exec(SCHEMA_TABLES);
|
||||
|
||||
Reference in New Issue
Block a user