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

オープン
#67,427 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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時間
マージ済み PR(30日)
266

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nodejs/node のほかの issue

nodejs/node の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。