Title: sqlite: should `Database` close its connection on garbage collection? · Issue #67427 · nodejs/node · GitHub
Open Graph Title: sqlite: should `Database` close its connection on garbage collection? · Issue #67427 · nodejs/node
X Title: sqlite: should `Database` close its connection on garbage collection? · Issue #67427 · nodejs/node
Description: 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...
Open Graph Description: 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 conne...
X Description: 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 conne...
Opengraph URL: https://github.com/nodejs/node/issues/67427
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"sqlite: should `Database` close its connection on garbage collection?","articleBody":"### Background\n\nIf a `Database` is garbage-collected while still open, its destructor ([`Database::~Database()` in `src/node_sqlite.cc`](https://github.com/nodejs/node/blob/main/src/node_sqlite.cc)) finalizes outstanding statements, deletes sessions, and closes the connection without notice.\n\n`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](https://nodejs.org/api/deprecations.html#DEP0137)). @BurningEnlightenment raised this in #57445 as something to settle before `node:sqlite` is stable, because tightening the behavior afterward would be semver-major.\n\n### Why it might matter for SQLite\n\n- 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.\n- A connection closed implicitly can hide bugs, such as a forgotten `close()` in a transaction path.\n\n### Prior art\n\n- [better-sqlite3](https://github.com/WiseLibs/better-sqlite3/blob/master/src/objects/database.cpp) 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).\n- SQLite's official WASM build ([`@sqlite.org/sqlite-wasm`](https://github.com/sqlite/sqlite-wasm)) never closes on GC. Its docs say GC \"will never trigger close()\", so an unclosed connection leaks.\n- `fs.FileHandle` went from closing on GC to throwing ([DEP0137](https://nodejs.org/api/deprecations.html#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.\n- `using` / `Symbol.dispose` already provide explicit cleanup.\n\n### Options\n\n1. Keep the current behavior and document it as guaranteed.\n2. Keep closing on GC, but emit a warning when it happens. This could be added later without being semver-major.\n3. Follow DEP0137: deprecate, then throw.\n\nWhich behavior do we want to commit to for the stable API?\n","author":{"url":"https://github.com/TrevorBurnham","@type":"Person","name":"TrevorBurnham"},"datePublished":"2026-11-12T02:15:17Z","url":"https://github.com/nodejs/node/issues/67427"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fd8d21e5-fc13-126d-1b4b-cad3adefeaf3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BF6A:65478:2CE28C4:3B952D4:6B01C69B |
| html-safe-nonce | 5fea57b14bf51e8fa2f837aad53de866f598d30147829c7a65f0e307f946cad7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjZBOjY1NDc4OjJDRTI4QzQ6M0I5NTJENDo2QjAxQzY5QiIsInZpc2l0b3JfaWQiOiIxOTA2NzIxMzEyMzI4NTAwODkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8d2698ebd7adb968536e69272ea4449b3b43f3f9df091f5c799443a012eefe0c |
| hovercard-subject-tag | issue:6341168764 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/67427/issue_layout |
| twitter:image | https://opengraph.githubassets.com/de83ba6ebc81f98500376710dd2e2342f873e021e0f87ac5eb408e368bebb7d6/nodejs/node/issues/67427 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/de83ba6ebc81f98500376710dd2e2342f873e021e0f87ac5eb408e368bebb7d6/nodejs/node/issues/67427 |
| og:image:alt | 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 conne... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TrevorBurnham |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width