Skip to content

sqlite: prevent reentrant statement finalization - #64796

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:sqlite-reject-reentrant-close
Open

sqlite: prevent reentrant statement finalization#64796
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:sqlite-reject-reentrant-close

Conversation

@trivikr

@trivikr trivikr commented Jul 28, 2026

Copy link
Copy Markdown
Member

Fixes: #64795

A scalar or aggregate callback can call db.close() while its prepared
statement is executing inside sqlite3_step(). close() then finalizes the
currently executing statement, and execution resumes with an invalid statement,
causing the process to crash. db.deserialize() has the same issue because it
also finalizes existing statements.

This change tracks statement execution depth around sqlite3_step() and
rejects close() and deserialize() with ERR_INVALID_STATE while a statement
is executing.


Assisted-by: codex:gpt-5.6-sol

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

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.16%. Comparing base (bec3d0b) to head (4af37c6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64796      +/-   ##
==========================================
+ Coverage   90.14%   90.16%   +0.01%     
==========================================
  Files         746      746              
  Lines      242763   242769       +6     
  Branches    45761    45769       +8     
==========================================
+ Hits       218848   218900      +52     
+ Misses      15402    15351      -51     
- Partials     8513     8518       +5     
Files with missing lines Coverage Δ
src/node_sqlite.cc 80.92% <100.00%> (+0.04%) ⬆️
src/node_sqlite.h 80.64% <ø> (ø)

... and 36 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 the request-ci Add this label to start a Jenkins CI on a PR. label Jul 28, 2026
Track statement execution depth while calling sqlite3_step(). Reject
close() and deserialize() while a statement is executing so callbacks
cannot finalize the active statement and crash.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: codex:gpt-5.6-sol
@trivikr
trivikr force-pushed the sqlite-reject-reentrant-close branch from c11abfd to 4af37c6 Compare July 31, 2026 04:28
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. request-ci Add this label to start a Jenkins CI on a PR. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: prevent reentrant statement finalization from callbacks

2 participants