Skip to content

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

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

trivikr wants to merge 1 commit 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
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 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.40%. Comparing base (bbd566d) to head (5925401).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66519      +/-   ##
==========================================
- Coverage   92.74%   90.40%   -2.35%     
==========================================
  Files         422      791     +369     
  Lines      193170   275991   +82821     
  Branches    29783    52980   +23197     
==========================================
+ Hits       179160   249505   +70345     
- Misses      13682    16902    +3220     
- Partials      328     9584    +9256     
Files with missing lines Coverage Δ
src/node_sqlite.cc 81.94% <100.00%> (ø)

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

sqlite: exhausted iterators incorrectly receive return()

2 participants