Skip to content

sqlite: skip return() on exhausted virtual table iterators - #66519

Open
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:sqlite-exhausted-iterators-return-2
Open

trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:sqlite-exhausted-iterators-return-2

Conversation

@trivikr

@trivikr trivikr commented Oct 5, 2026

Copy link
Copy Markdown
Member

Fixes: #66518

Once a virtual table iterator's next() reports done: true, the iterator is finished, so return() must not be called. This matches for...of, which calls return() only on abrupt termination. Before this change, an empty custom iterable with a throwing return() made an otherwise successful query fail.

CloseIterator() now skips cursors whose iteration has completed. That covers both xClose and cursor re-filtering. Early termination (LIMIT, break, re-filter mid-scan) still calls return().


Assisted-by: claude:opus-5.5

@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 Oct 5, 2026
@trivikr
trivikr force-pushed the sqlite-exhausted-iterators-return-2 branch from bbd7a1b to 5925401 Compare October 5, 2026 16:37
@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.59%. Comparing base (221b47d) to head (aa5cfc6).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66519      +/-   ##
==========================================
+ Coverage   90.57%   90.59%   +0.01%     
==========================================
  Files         797      797              
  Lines      278362   278364       +2     
  Branches    53497    53500       +3     
==========================================
+ Hits       252138   252189      +51     
+ Misses      16574    16521      -53     
- Partials     9650     9654       +4     
Files with missing lines Coverage Δ
src/node_sqlite.cc 81.90% <100.00%> (-0.05%) ⬇️

... and 29 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 requested a review from araujogui October 6, 2026 01:51
@trivikr trivikr 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 Oct 6, 2026
@trivikr

trivikr commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

cc @araujogui can you review this?

@trivikr
trivikr requested a review from Renegade334 October 14, 2026 19:05

@araujogui araujogui 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.

nit: might be worth a line in the createModule() docs on when return() gets called.

Comment thread src/node_sqlite.cc
Comment thread src/node_sqlite.cc
Comment thread test/parallel/test-sqlite-virtual-table.js
Comment thread test/parallel/test-sqlite-virtual-table.js Outdated
Closing a virtual table cursor invoked the iterator's return() even
after next() had already reported done: true, deviating from for...of
semantics where return() only runs on abrupt termination. An empty
custom iterable with a throwing return() made an otherwise successful
query fail.

Only close the iterator when the scan stopped early, as with LIMIT, a
break, or a cursor re-filter; a normally finished iterator already ran
its cleanup.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5.5
@trivikr
trivikr force-pushed the sqlite-exhausted-iterators-return-2 branch from 5925401 to b18715a Compare October 21, 2026 06:46
sqlite: skip return() on exhausted virtual table iterators

Closing a virtual table cursor invoked the iterator's return() even
after next() had already reported done: true, deviating from for...of
semantics where return() only runs on abrupt termination. An empty
custom iterable with a throwing return() made an otherwise successful
query fail.

Only close the iterator when the scan stopped early, as with LIMIT, a
break, or a cursor re-filter; a normally finished iterator already ran
its cleanup.

Likewise, skip return() after an iterator protocol error, where next()
is missing or returns a non-object, as for...of does not close the
iterator in that case.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5.5
@trivikr
trivikr requested a review from araujogui October 21, 2026 07:02
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. Only starts once the PR has an approving review. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: exhausted iterators incorrectly receive return()

3 participants