Skip to content

sqlite: re-filtering a virtual-table cursor skips generator cleanup #66193

Description

@trivikr

Version

main

Platform

N/A

Subsystem

sqlite

What steps will reproduce the bug?

import { DatabaseSync } from 'node:sqlite';

const db = new DatabaseSync(':memory:');

let cleaned = 0;
db.createModule('m', {
  columns: [{ name: 'input', type: 'INTEGER', hidden: true }],
  *rows(input) {
    try { yield [input]; } finally { cleaned++; }
  },
});

db.exec('CREATE TABLE t(a); INSERT INTO t VALUES (1), (2)');
db.prepare('SELECT a FROM t WHERE EXISTS(SELECT 1 FROM m(t.a))').all();
console.log(cleaned);  // 1, expected 2

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Both rows() calls (for t.a = 1 and t.a = 2) run their finally, so cleaned is 2.

What do you see instead?

cleaned is 1; the first generator is suspended and discarded by the re-filter and its finally never runs.

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

sqliteIssues and PRs related to the SQLite subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions