Skip to content

sqlite: prevent database close during callbacks#64743

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-sqlite-close-during-callback
Open

sqlite: prevent database close during callbacks#64743
mcollina wants to merge 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 57.14286% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.15%. Comparing base (e6a8d06) to head (822fbef).
⚠️ Report is 462 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 42.85% 8 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64743      +/-   ##
==========================================
- Coverage   92.01%   90.15%   -1.87%     
==========================================
  Files         379      744     +365     
  Lines      166972   242541   +75569     
  Branches    25554    45697   +20143     
==========================================
+ Hits       153639   218659   +65020     
- Misses      13041    15370    +2329     
- Partials      292     8512    +8220     
Files with missing lines Coverage Δ
src/node_sqlite.h 82.60% <100.00%> (ø)
src/node_sqlite.cc 80.42% <42.85%> (ø)

... and 573 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 from 4798627 to d3160fe Compare July 26, 2026 06:51
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 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

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.

5 participants