Title: node:sqlite: process crash (SIGSEGV) when a Session outlives its garbage-collected DatabaseSync · Issue #63796 · nodejs/node · GitHub
Open Graph Title: node:sqlite: process crash (SIGSEGV) when a Session outlives its garbage-collected DatabaseSync · Issue #63796 · nodejs/node
X Title: node:sqlite: process crash (SIGSEGV) when a Session outlives its garbage-collected DatabaseSync · Issue #63796 · nodejs/node
Description: Version v27.0.0-pre Platform Linux x64 (platform-independent) Subsystem sqlite What steps will reproduce the bug? database.createSession() returns a Session that holds only a weak reference to its DatabaseSync. If the database becomes un...
Open Graph Description: Version v27.0.0-pre Platform Linux x64 (platform-independent) Subsystem sqlite What steps will reproduce the bug? database.createSession() returns a Session that holds only a weak reference to its ...
X Description: Version v27.0.0-pre Platform Linux x64 (platform-independent) Subsystem sqlite What steps will reproduce the bug? database.createSession() returns a Session that holds only a weak reference to its ...
Opengraph URL: https://github.com/nodejs/node/issues/63796
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"node:sqlite: process crash (SIGSEGV) when a Session outlives its garbage-collected DatabaseSync","articleBody":"### Version\n\nv27.0.0-pre\n\n### Platform\n\n```text\nLinux x64 (platform-independent)\n```\n\n### Subsystem\n\nsqlite\n\n### What steps will reproduce the bug?\n\n`database.createSession()` returns a `Session` that holds only a weak reference to its `DatabaseSync`. If the database becomes unreachable and is garbage-collected while the session is still alive, calling any session method dereferences the now-null weak pointer and crashes the process.\n\n```\n// run with: node --expose-gc --experimental-sqlite repro.js\nconst { DatabaseSync } = require('node:sqlite');\n\nfunction createSession() {\n const db = new DatabaseSync(':memory:');\n db.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');\n return db.createSession(); // session keeps only a WEAK ref to db\n}\n\nconst session = createSession(); // no strong reference to db survives\nglobal.gc(); // DatabaseSync is collected here\n\nsession.changeset(); // SIGSEGV (also: .patchset(), .close(), Symbol.dispose)\n```\n\n### How often does it reproduce? Is there a required condition?\n\nDeterministically, once the `DatabaseSync` has actually been collected.\n\n\n\n### What is the expected behavior? Why is that the expected behavior?\n\nA thrown Error (code: 'ERR_INVALID_STATE', message \"database is not open\"), consistent with database.limits and other post-close paths... not a process crash.\n\n\n\n### What do you see instead?\n\nSegmentation fault (core dumped) # exit 139\nGDB shows the fault in `node::sqlite::Session::Changeset` at instruction `cmpq $0x0,0xc0(%rax)` with `%rax = 0`\n\n### Additional information\n\nRoot cause: Session held only a weak reference to its DatabaseSync, unlike StatementSync (from database.prepare()), which holds a strong reference and keeps its database alive. When the database handle is dropped and collected while the session is still reachable, the weak pointer is nulled and Session::Changeset/Close dereference it via !session->database_->IsOpen(), reading connection_ through a null this. The session should instead keep the database alive, collection of the db handle is not the same as the user calling database.close().\n\n\n","author":{"url":"https://github.com/3zrv","@type":"Person","name":"3zrv"},"datePublished":"2026-06-08T16:20:57Z","url":"https://github.com/nodejs/node/issues/63796"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:3f130fb4-ddaa-b27d-a461-cb8480217b39 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 938E:B3C94:706931:921E3C:6AED3055 |
| html-safe-nonce | b3a3fa892a4b31fdf07347e3b40ee071c37570404b38121a08cfcf4497b0ad6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzhFOkIzQzk0OjcwNjkzMTo5MjFFM0M6NkFFRDMwNTUiLCJ2aXNpdG9yX2lkIjoiNDU5ODcxMDE2MzgxMDg4OTgxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 834b1d88f996352217036068b606c13905433ab404520f7c217e6a820eb5b38d |
| hovercard-subject-tag | issue:4614610316 |
| 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/63796/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4f7991ee07714aec6df84dec92cb55b4e16a6f74fbe712befb703523a1038e53/nodejs/node/issues/63796 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4f7991ee07714aec6df84dec92cb55b4e16a6f74fbe712befb703523a1038e53/nodejs/node/issues/63796 |
| og:image:alt | Version v27.0.0-pre Platform Linux x64 (platform-independent) Subsystem sqlite What steps will reproduce the bug? database.createSession() returns a Session that holds only a weak reference to its ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 3zrv |
| hostname | github.com |
| expected-hostname | github.com |
| None | e51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a |
| 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 | 59ebb7b901cc154ecc179a44f266fcf69f343b30 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width