sqlite: should `Database` close its connection on garbage collection?
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, sqlite
调研方向
Start by reading Database::~Database() in src/node_sqlite.cc and the linked DEP0137 discussion for context. The issue asks maintainers to choose and commit to a stable API behavior for garbage-collected open databases; done means that policy is decided, with any follow-up implementation or documentation scoped from that decision.
由索引模型根据 Issue 内容生成。
描述
Background
If a Database is garbage-collected while still open, its destructor (Database::~Database() in src/node_sqlite.cc) finalizes outstanding statements, deletes sessions, and closes the connection without notice.
fs.FileHandle used to behave the same way and moved away from it. Closing on GC was runtime-deprecated in v14 and became End-of-Life (it throws) in v25 (DEP0137). @BurningEnlightenment raised this in #57445 as something to settle before node:sqlite is stable, because tightening the behavior afterward would be semver-major.
Why it might matter for SQLite
- Until it's collected, an unclosed connection keeps its file locks, and in WAL mode it may delay the checkpoint. That timing depends on GC, so other connections or processes can hit
SQLITE_BUSYat unpredictable times. - A connection closed implicitly can hide bugs, such as a forgotten
close()in a transaction path.
Prior art
- better-sqlite3 does what we do today: its destructor finalizes statements and closes the connection without notice, and it closes any remaining connections when the addon unloads. Matching it eases migration, which is a frequent request (e.g. #67353).
- SQLite's official WASM build (
@sqlite.org/sqlite-wasm) never closes on GC. Its docs say GC "will never trigger close()", so an unclosed connection leaks. fs.FileHandlewent from closing on GC to throwing (DEP0137). Part of the reason was async operations racing a GC-driven close, which doesn't apply here: allnode:sqliteoperations are synchronous, so nothing can be in flight when the destructor runs.using/Symbol.disposealready provide explicit cleanup.
Options
- Keep the current behavior and document it as guaranteed.
- Keep closing on GC, but emit a warning when it happens. This could be added later without being semver-major.
- Follow DEP0137: deprecate, then throw.
Which behavior do we want to commit to for the stable API?
- 主要语言
- JavaScript
- 星标
- 124k
- 派生
- 38k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 266
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nodejs/node 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 69/100
维护者通常 1 天内回复
-
fs: document readStream.start and readStream.end可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭doc
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
-
doc: document the Buffer.prototype.*Slice() methods可能已有人在做 @AyushCipher 今天认领。 未关闭doc
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
`styleText` fast path bypasses `options` and `options.validateStream` validation可能已有人在做 @GBra-4-669 于 8 天前认领。 未关闭util
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
riscv64
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
相似的 Issue
-
bug triage needed
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
resource-submission validation-passed
难度 1/5 1 小时以内 新手友好度 82/100
hesreallyhim/awesome-claude-code#3773 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 73/100
tabatkins/railroad-diagrams#129 ·
-
web: api() turns a null or object-valued error body into a TypeError or "[object Object]" and loses the status可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复