Skip to content

sqlite: restore connection state on reopen - #66042

Open
araujogui wants to merge 1 commit into
nodejs:mainfrom
araujogui:sqlite-reopen-state
Open

araujogui wants to merge 1 commit into
nodejs:mainfrom
araujogui:sqlite-reopen-state

Conversation

@araujogui

Copy link
Copy Markdown
Member

close() destroys the SQLite connection but keeps the DatabaseSync object, and Open() did not replay the state held on that object.

db.setAuthorizer(() => constants.SQLITE_DENY);
db.exec('CREATE TABLE x(a)');  // throws, as expected
db.close(); db.open();
db.exec('CREATE TABLE x(a)');  // succeeds — policy silently gone

Three cases:

  • The authorizer lives in an internal field that outlives the connection. It was never re-registered, so the object reported an authorizer SQLite was no longer consulting.
  • Limits written through db.limits.* went only to the connection, so they reverted to the constructor values.
  • Extension loading was re-enabled from allow_load_extension_ (the constructor ceiling) instead of enable_load_extension_ (the current setting). db.loadExtension() stayed blocked by its JS guard, but the SQL load_extension() function did not.

Fix: re-register the authorizer at the end of Open(), record runtime limit writes alongside the constructor options so both are replayed, and apply the current load-extension setting rather than the ceiling.

close() destroys the connection but keeps the DatabaseSync object, and
open() did not replay the state held on it.

An authorizer set with setAuthorizer() was not reinstalled, silently
dropping a deny-all policy. Limits written through db.limits.* reverted
to the constructor values. Extension loading was re-enabled from the
constructor ceiling rather than the current setting, leaving the SQL
load_extension() function reachable after enableLoadExtension(false).

Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Assisted-by: Claude Code
Copilot AI lite review requested due to automatic review settings September 15, 2026 22:12
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.21%. Comparing base (c1e2478) to head (62d9d39).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66042      +/-   ##
==========================================
- Coverage   90.23%   90.21%   -0.02%     
==========================================
  Files         785      789       +4     
  Lines      269670   270622     +952     
  Branches    51589    51802     +213     
==========================================
+ Hits       243325   244152     +827     
- Misses      16825    16943     +118     
- Partials     9520     9527       +7     
Files with missing lines Coverage Δ
src/node_sqlite.h 86.40% <100.00%> (ø)
src/node_sqlite.cc 82.10% <92.85%> (+0.02%) ⬆️

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

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. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants