sqlite: should `Database` close its connection on garbage collection?

未关闭
#67,427 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, sqlite
领域
backend, databases

调研方向

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 内容生成。

描述

question sqlite
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_BUSY at 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.FileHandle went from closing on GC to throwing (DEP0137). Part of the reason was async operations racing a GC-driven close, which doesn't apply here: all node:sqlite operations are synchronous, so nothing can be in flight when the destructor runs.
  • using / Symbol.dispose already provide explicit cleanup.
Options
  1. Keep the current behavior and document it as guaranteed.
  2. Keep closing on GC, but emit a warning when it happens. This could be added later without being semver-major.
  3. 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

环境准备

从这里开始

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

nodejs/node 的其他 Issue

查看 nodejs/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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