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

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
@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.13%. Comparing base (6a3d80f) to head (c11abfd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64796      +/-   ##
==========================================
- Coverage   90.16%   90.13%   -0.04%     
==========================================
  Files         744      744              
  Lines      242518   242524       +6     
  Branches    45705    45693      -12     
==========================================
- Hits       218670   218601      -69     
- Misses      15357    15422      +65     
- Partials     8491     8501      +10     
Files with missing lines Coverage Δ
src/node_sqlite.cc 80.71% <100.00%> (+0.04%) ⬆️
src/node_sqlite.h 80.64% <ø> (ø)

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