Bug (latent)
withZoteroDbExclusive() in packages/editor-server/src/core/zotero/local/db.ts:74 does:
try {
db = new Database(...);
...
return f(db); // f: (db) => Promise<T>
} finally {
if (db) db.close(); // runs as soon as f returns its promise
...
}
Because f(db) is returned without await, the finally runs as soon as f hands back its promise, not when that promise settles. If f ever awaits anything before it finishes using db, the database is closed out from under it, and the next db.all(...) throws.
Current status
It doesn't bite today. The node-sqlite3-wasm API is synchronous, and all three callers in source.ts (lines ~36, ~95, ~120) are async callbacks that never await, so their DB work finishes synchronously before the promise is returned. The trap is that anyone who adds an await inside one of those callbacks (a network call to the Zotero web API, a file read, etc.) breaks it, and the resulting "database closed" error will be confusing.
Fix
That's the whole change. withZoteroDbExclusive is already async, so this just moves close() until after f settles. Consider adding a unit test with a callback that awaits (e.g. await Promise.resolve()) before querying.
Found during the dependency-upgrade research.
Bug (latent)
withZoteroDbExclusive()inpackages/editor-server/src/core/zotero/local/db.ts:74does:Because
f(db)is returned withoutawait, thefinallyruns as soon asfhands back its promise, not when that promise settles. Iffever awaits anything before it finishes usingdb, the database is closed out from under it, and the nextdb.all(...)throws.Current status
It doesn't bite today. The node-sqlite3-wasm API is synchronous, and all three callers in
source.ts(lines ~36, ~95, ~120) areasynccallbacks that neverawait, so their DB work finishes synchronously before the promise is returned. The trap is that anyone who adds anawaitinside one of those callbacks (a network call to the Zotero web API, a file read, etc.) breaks it, and the resulting "database closed" error will be confusing.Fix
That's the whole change.
withZoteroDbExclusiveis alreadyasync, so this just movesclose()until afterfsettles. Consider adding a unit test with a callback thatawaits (e.g.await Promise.resolve()) before querying.Found during the dependency-upgrade research.