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 摘要。