Issue
kysely-wasqlite-worker leaves a prepared statement open in the normal queryData path. After running ordinary Kysely queries through the worker, closing the database can fail with:
unable to close due to unfinalized statements or unfinished backups
The current source has the suspected manual iterator usage in packages/dialect-wasqlite-worker/src/worker/utils.ts.
The same file's streaming path uses for await, which should invoke iterator cleanup automatically: utils.ts#L70-L106.
Suspected cause
In queryData, the code manually creates an async iterator from core.sqlite.statements(core.pointer, sql), calls next(), and keeps the yielded statement. It does not call return() on that iterator after the query finishes.
@subframe7536/sqlite-wasm documents that statements(...) owns the prepared statement lifetime through the iterator. It also explicitly says that manual iterator users, such as code calling next() directly, should call return() when iteration is abandoned so allocated resources are released: sqlite-wasm/src/types/api.ts#L529-L566.
That matches the observed close failure. SQLite itself reports a close error when there are unfinalized prepared statements: sqlite3_close and sqlite3_prepare_v3.
Minimal Reproduction
See repo with svelte kit minimal reproduction.
Issue
kysely-wasqlite-workerleaves a prepared statement open in the normalqueryDatapath. After running ordinary Kysely queries through the worker, closing the database can fail with:The current source has the suspected manual iterator usage in
packages/dialect-wasqlite-worker/src/worker/utils.ts.The same file's streaming path uses
for await, which should invoke iterator cleanup automatically:utils.ts#L70-L106.Suspected cause
In
queryData, the code manually creates an async iterator fromcore.sqlite.statements(core.pointer, sql), callsnext(), and keeps the yielded statement. It does not callreturn()on that iterator after the query finishes.@subframe7536/sqlite-wasmdocuments thatstatements(...)owns the prepared statement lifetime through the iterator. It also explicitly says that manual iterator users, such as code callingnext()directly, should callreturn()when iteration is abandoned so allocated resources are released:sqlite-wasm/src/types/api.ts#L529-L566.That matches the observed close failure. SQLite itself reports a close error when there are unfinalized prepared statements:
sqlite3_closeandsqlite3_prepare_v3.Minimal Reproduction
See repo with svelte kit minimal reproduction.