Skip to content

sqlite: keep database alive while a session is open#63797

Open
3zrv wants to merge 3 commits into
nodejs:mainfrom
3zrv:fix/sqlite-session-crash
Open

sqlite: keep database alive while a session is open#63797
3zrv wants to merge 3 commits into
nodejs:mainfrom
3zrv:fix/sqlite-session-crash

Conversation

@3zrv

@3zrv 3zrv commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

fixes: #63796

Verification

  • Repro crashes (SIGSEGV, exit 139) before the change; throws ERR_INVALID_STATE after.
  • New regression test fails (segfault) on an unfixed build and passes on the fixed build.
  • Full test/parallel/test-sqlite-session.js suite passes (26/26).

Signed-off-by: Mohamed Sayed <k@3zrv.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Jun 8, 2026
@louwers

louwers commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

I think a session is supposed to keep the database alive...

Signed-off-by: Mohamed Sayed <k@3zrv.com>
@3zrv 3zrv changed the title sqlite: fix crash when a session outlives its database sqlite: keep database alive while a session is open Jun 8, 2026
@3zrv

3zrv commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@louwers totally right, the bug was that the session held the database with a weak ref, so it could get GC'd out from under a live session -> dangling pointer -> crash. sqlite requires sessions to be deleted before the connection closes, so a live session with a dead DB is never valid

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.14%. Comparing base (34c28d5) to head (f6b4960).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63797      +/-   ##
==========================================
- Coverage   90.23%   90.14%   -0.10%     
==========================================
  Files         739      741       +2     
  Lines      241639   241978     +339     
  Branches    45547    45538       -9     
==========================================
+ Hits       218031   218119      +88     
- Misses      15152    15374     +222     
- Partials     8456     8485      +29     
Files with missing lines Coverage Δ
src/node_sqlite.h 80.64% <ø> (ø)
src/node_sqlite.cc 80.65% <25.00%> (-0.06%) ⬇️

... and 68 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:sqlite: process crash (SIGSEGV) when a Session outlives its garbage-collected DatabaseSync

4 participants