Skip to content

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

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

sqlite: keep database alive while a session is open#63797
3zrv wants to merge 5 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.13%. Comparing base (db3a8d8) to head (c0e9004).
⚠️ Report is 7 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.14%   90.13%   -0.01%     
==========================================
  Files         741      741              
  Lines      242133   242135       +2     
  Branches    45568    45562       -6     
==========================================
- Hits       218265   218244      -21     
- Misses      15371    15401      +30     
+ Partials     8497     8490       -7     
Files with missing lines Coverage Ξ”
src/node_sqlite.h 80.64% <ΓΈ> (ΓΈ)
src/node_sqlite.cc 80.65% <25.00%> (-0.06%) ⬇️

... and 28 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.

@trivikr trivikr added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jul 21, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 21, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@geeksilva97 geeksilva97 added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jul 21, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 21, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/63797
βœ”  Done loading data for nodejs/node/pull/63797
----------------------------------- PR info ------------------------------------
Title      sqlite: keep database alive while a session is open (#63797)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     3zrv:fix/sqlite-session-crash -> nodejs:main
Labels     c++, author ready, needs-ci, commit-queue-squash, sqlite
Commits    3
 - sqlite: fix crash when a session outlives its database
 - fix: keep database alive while a session is open
 - Merge branch 'main' into fix/sqlite-session-crash
Committers 1
 - Mohamed Sayed <k@3zrv.com>
PR-URL: https://github.com/nodejs/node/pull/63797
Fixes: https://github.com/nodejs/node/issues/63796
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/63797
Fixes: https://github.com/nodejs/node/issues/63796
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
--------------------------------------------------------------------------------
   β„Ή  This PR was created on Mon, 08 Jun 2026 16:23:46 GMT
   βœ”  Approvals: 2
   βœ”  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/63797#pullrequestreview-4731067200
   βœ”  - Edy Silva (@geeksilva97): https://github.com/nodejs/node/pull/63797#pullrequestreview-4744533536
   ⚠  GitHub cannot link the author of 'sqlite: fix crash when a session outlives its database' to their GitHub account.
   ⚠  Please suggest them to take a look at https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork
   ⚠  GitHub cannot link the author of 'fix: keep database alive while a session is open' to their GitHub account.
   ⚠  Please suggest them to take a look at https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork
   ⚠  GitHub cannot link the author of 'Merge branch 'main' into fix/sqlite-session-crash' to their GitHub account.
   ⚠  Please suggest them to take a look at https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork
   βœ”  Last GitHub CI successful
   β„Ή  Last Full PR CI on 2026-07-21T12:30:19Z: https://ci.nodejs.org/job/node-test-pull-request/74960/
- Querying data for job/node-test-pull-request/74960/
βœ”  Build data downloaded
   βœ”  Last Jenkins CI successful
--------------------------------------------------------------------------------
   βœ”  No git cherry-pick in progress
   βœ”  No git am in progress
   βœ”  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
βœ”  origin/main is now up-to-date
- Downloading patch for 63797
From https://github.com/nodejs/node
 * branch                  refs/pull/63797/merge -> FETCH_HEAD
βœ”  Fetched commits as 69e982f70d31..f6b496025e59
--------------------------------------------------------------------------------
Auto-merging src/node_sqlite.cc
Auto-merging test/parallel/test-sqlite-session.js
[main ed54edc94a] sqlite: fix crash when a session outlives its database
 Author: Mohamed Sayed <k@3zrv.com>
 Date: Mon Jun 8 19:21:31 2026 +0300
 2 files changed, 35 insertions(+), 3 deletions(-)
Auto-merging src/node_sqlite.cc
Auto-merging test/parallel/test-sqlite-session.js
error: commit f6b496025e5974385c8adea13857b5fd7d810171 is a merge but no -m option was given.
fatal: cherry-pick failed
[main aca4f7c47a] fix: keep database alive while a session is open Signed-off-by: Mohamed Sayed <k@3zrv.com>
 Author: Mohamed Sayed <k@3zrv.com>
 Date: Mon Jun 8 20:26:15 2026 +0300
 3 files changed, 31 insertions(+), 31 deletions(-)
   ✘  Failed to apply patches
https://github.com/nodejs/node/actions/runs/29837964050

@geeksilva97

Copy link
Copy Markdown
Contributor

Could you rebase this, @3zrv ?

@3zrv

3zrv commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

should be good now, thank you @geeksilva97

@geeksilva97 geeksilva97 added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jul 22, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@geeksilva97 geeksilva97 added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jul 22, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/63797
βœ”  Done loading data for nodejs/node/pull/63797
----------------------------------- PR info ------------------------------------
Title      sqlite: keep database alive while a session is open (#63797)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     3zrv:fix/sqlite-session-crash -> nodejs:main
Labels     c++, author ready, needs-ci, commit-queue-squash, sqlite
Commits    4
 - sqlite: fix crash when a session outlives its database
 - fix: keep database alive while a session is open
 - Merge branch 'main' into fix/sqlite-session-crash
 - Merge branch 'main' into fix/sqlite-session-crash
Committers 1
 - Mohamed Sayed <k@3zrv.com>
PR-URL: https://github.com/nodejs/node/pull/63797
Fixes: https://github.com/nodejs/node/issues/63796
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/63797
Fixes: https://github.com/nodejs/node/issues/63796
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
--------------------------------------------------------------------------------
   β„Ή  This PR was created on Mon, 08 Jun 2026 16:23:46 GMT
   βœ”  Approvals: 2
   βœ”  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/63797#pullrequestreview-4731067200
   βœ”  - Edy Silva (@geeksilva97): https://github.com/nodejs/node/pull/63797#pullrequestreview-4749964087
   ⚠  GitHub cannot link the author of 'sqlite: fix crash when a session outlives its database' to their GitHub account.
   ⚠  Please suggest them to take a look at https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork
   ⚠  GitHub cannot link the author of 'fix: keep database alive while a session is open' to their GitHub account.
   ⚠  Please suggest them to take a look at https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork
   ⚠  GitHub cannot link the author of 'Merge branch 'main' into fix/sqlite-session-crash' to their GitHub account.
   ⚠  Please suggest them to take a look at https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork
   ⚠  GitHub cannot link the author of 'Merge branch 'main' into fix/sqlite-session-crash' to their GitHub account.
   ⚠  Please suggest them to take a look at https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork
   βœ”  Last GitHub CI successful
   β„Ή  Last Full PR CI on 2026-07-22T03:17:01Z: https://ci.nodejs.org/job/node-test-pull-request/74990/
- Querying data for job/node-test-pull-request/74990/
βœ”  Build data downloaded
   βœ”  Last Jenkins CI successful
--------------------------------------------------------------------------------
   βœ”  No git cherry-pick in progress
   βœ”  No git am in progress
   βœ”  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
βœ”  origin/main is now up-to-date
- Downloading patch for 63797
From https://github.com/nodejs/node
 * branch                  refs/pull/63797/merge -> FETCH_HEAD
βœ”  Fetched commits as 15d5b8f7fecc..c0e90048ea8a
--------------------------------------------------------------------------------
Auto-merging src/node_sqlite.cc
Auto-merging test/parallel/test-sqlite-session.js
[main 9755c48553] sqlite: fix crash when a session outlives its database
 Author: Mohamed Sayed <k@3zrv.com>
 Date: Mon Jun 8 19:21:31 2026 +0300
 2 files changed, 35 insertions(+), 3 deletions(-)
Auto-merging src/node_sqlite.cc
Auto-merging test/parallel/test-sqlite-session.js
error: commit f6b496025e5974385c8adea13857b5fd7d810171 is a merge but no -m option was given.
fatal: cherry-pick failed
[main 05d775e278] fix: keep database alive while a session is open Signed-off-by: Mohamed Sayed <k@3zrv.com>
 Author: Mohamed Sayed <k@3zrv.com>
 Date: Mon Jun 8 20:26:15 2026 +0300
 3 files changed, 31 insertions(+), 31 deletions(-)
   ✘  Failed to apply patches
https://github.com/nodejs/node/actions/runs/29926645472

@geeksilva97

Copy link
Copy Markdown
Contributor

I suspect these merge commits are messing with the bot that merges the PR. Could you squash all your commits into a single one?

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. 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

6 participants