Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Local Zotero: withZoteroDb closes the DB before an async callback finishes (missing await)

未关闭 适合新手
#1,138 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1-3 小时
新手友好度
90/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
sqlite, typescript
领域
backend, databases

调研方向

从 packages/editor-server/src/core/zotero/local/db.ts 中的 withZoteroDbExclusive() 开始,然后检查 source.ts 中第 36、95 和 120 行附近的三个调用方。添加一个使用在查询前执行 await 的 callback 的回归测试,并运行相关的 editor-server 测试;完成的标准是数据库在异步 callback 完成之前始终可用,之后再关闭。

由索引模型根据 Issue 内容生成。

描述

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

return await f(db);

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.

主要语言
TypeScript
星标
652
派生
64
平均合并
8 小时 45 分钟
30 天内合并 PR
36

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quarto-dev/quarto 的其他 Issue

查看 quarto-dev/quarto 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。