Skip to content

sqlite: prevent database close during callbacks - #64743

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mcollina:fix-sqlite-close-during-callback
Aug 4, 2026
Merged

sqlite: prevent database close during callbacks#64743
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mcollina:fix-sqlite-close-during-callback

Conversation

@mcollina

@mcollina mcollina commented Jul 25, 2026

Copy link
Copy Markdown
Member

Prevent DatabaseSync.close() from finalizing SQLite resources while a JavaScript callback is executing.

SQLite invokes user-defined functions, aggregate functions, authorizers, and changeset callbacks synchronously during database operations. Previously, calling database.close() from one of these callbacks could finalize active statements or the connection while native code was still using them.

This change tracks callback depth and rejects reentrant closes with ERR_INVALID_STATE. It also adds regression coverage for StatementSync.all(), get(), run(), and iterate().

@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 Jul 25, 2026
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.29032% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.16%. Comparing base (c8e2a82) to head (a477a99).
⚠️ Report is 82 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 50.00% 8 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #64743   +/-   ##
=======================================
  Coverage   90.16%   90.16%           
=======================================
  Files         746      746           
  Lines      242760   242784   +24     
  Branches    45765    45766    +1     
=======================================
+ Hits       218875   218902   +27     
+ Misses      15375    15367    -8     
- Partials     8510     8515    +5     
Files with missing lines Coverage Δ
src/node_sqlite.h 82.60% <100.00%> (+1.96%) ⬆️
src/node_sqlite.cc 80.43% <50.00%> (-0.25%) ⬇️

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

@mcollina
mcollina force-pushed the fix-sqlite-close-during-callback branch 2 times, most recently from d3160fe to 822fbef Compare July 26, 2026 07:31

@mertcanaltin mertcanaltin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the guards in the base functions, and the window functions are covered too

and I looked fail test, this fail unrelated this pr

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

Copy link
Copy Markdown
Collaborator

Co-authored-by: Asroy Cristian Sitorus <asroycristiansitorus@gmail.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina force-pushed the fix-sqlite-close-during-callback branch from 822fbef to a477a99 Compare July 30, 2026 20:21
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 4, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 4, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina mcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 4, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 4, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 5cef767 into nodejs:main Aug 4, 2026
70 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 5cef767

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++. 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.

7 participants