Skip to content

sqlite: skip query trace while an exception is pending - #67538

Open
gengjiawen wants to merge 1 commit into
nodejs:mainfrom
gengjiawen:sqlite-trace-pending-exception
Open

gengjiawen wants to merge 1 commit into
nodejs:mainfrom
gengjiawen:sqlite-trace-pending-exception

Conversation

@gengjiawen

Copy link
Copy Markdown
Member

Summary

Database::TraceCallback published the sqlite.db.query diagnostics channel from SQLite's profile callback without checking for a pending JavaScript exception. SQLite runs that callback from sqlite3_step() when a statement fails, and from sqlite3_reset(), so a throwing SQL function or an out-of-range integer conversion entered subscriber JavaScript while an exception was already set. Debug builds abort in V8 Invoke. Release builds drop the original error or replace it with an empty ERR_SQLITE_ERROR.

Return before publishing when the isolate has a pending exception or JavaScript cannot be entered.

Test plan

  • node --expose-gc --test test/parallel/test-sqlite-diagnostic-channel.js
  • The new test covers a throwing SQL function and ERR_OUT_OF_RANGE from an integer that does not fit in a number, with an empty sqlite.db.query subscriber installed. A later successful query still reaches the subscriber.

Made with Cursor

@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 Nov 17, 2026
@gengjiawen
gengjiawen force-pushed the sqlite-trace-pending-exception branch from 28c28dd to a2b5f1f Compare November 17, 2026 09:58
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (bc6dd40) to head (821961b).
⚠️ Report is 45 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67538      +/-   ##
==========================================
+ Coverage   90.67%   90.71%   +0.03%     
==========================================
  Files         800      801       +1     
  Lines      280489   280707     +218     
  Branches    54166    54169       +3     
==========================================
+ Hits       254336   254632     +296     
+ Misses      16277    16254      -23     
+ Partials     9876     9821      -55     
Files with missing lines Coverage Δ
src/node_sqlite.cc 82.93% <50.00%> (+0.18%) ⬆️

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

Database::TraceCallback published sqlite.db.query from SQLite's
profile callback without checking for a pending JavaScript exception.
SQLite runs that callback from sqlite3_step() when a statement fails
and from sqlite3_reset(), so a throwing SQL function or an
out-of-range integer conversion called subscriber JS while an
exception was already set. Debug builds abort in V8's Invoke, and
release builds drop the original error or replace it with an empty
ERR_SQLITE_ERROR.

Return before publishing when the isolate has a pending exception or
JavaScript cannot be entered.

Assisted-by: Cursor Grok 4.7
Signed-off-by: gengjiawen <technicalcute@gmail.com>
@gengjiawen
gengjiawen force-pushed the sqlite-trace-pending-exception branch from a2b5f1f to 821961b Compare November 18, 2026 03:50
@gengjiawen gengjiawen added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 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

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