Repository navigation
Add close() and Symbol.dispose to SqlStorageCursor - #8692
Conversation
11d5a81 to
0ac4b60
Compare
There was a problem hiding this comment.
Superseded by the review of
12685c73.
This review, of 0ac4b60b
💬 Approved with comments — Correct, well-tested opt-in API addition. The only finding is an INFO: the wrong-IoContext fallback in close() loses the row counts and the tracing span tags.
Findings: 1 info (1 is an inline comment on the diff)
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.d.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
Correct on the same-IoContext path; the wrong-IoContext fallback in close() behaves differently and has no test.
Recommendation: 💬 Optional Nits
- [INFO] Wrong-IoContext fallback in close() skips endQuery(): row counts read as 0, the tracing span loses its tags, and the statement is freed later rather than right away; no test covers it. (
src/workerd/api/sql.c++:321)
View full review
Cursor::close() (src/workerd/api/sql.c++:315-325) delegates to endQuery() when the cursor's state belongs to the current IoContext. That path keeps the row counts, runs the tracing callback and drops the statement, as the description says.
The else branch handles a cursor whose state belongs to another IoContext. It clears doneCallback and state without calling endQuery(), which has three effects:
rowsReadandrowsWrittenkeep their defaults, so afterclose()the getters report 0 instead of the real counts, which contradicts the description's "kept".- The tracing callback is dropped without running, so the cursor's span never gets its
rows_readorrows_writtentags. - Releasing the
IoOwn<State>only queues the statement for deletion in the owning context, so it is not reset right away.
No test exercises this branch.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 0ac4b60b
0ac4b60 to
12685c7
Compare
There was a problem hiding this comment.
Superseded by the review of
669c2023.
This review, of 12685c73
✅ Approved — This is a correct, well-tested, opt-in API addition. The earlier wrong-IoContext note is fixed (close() now throws, like the cursor's other methods), and no new issues were found.
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.d.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
Cursor::close() now delegates to endQuery() whenever state is set. Calling it from another Durable Object throws, just as the cursor's other methods do, and the new closeOtherCursor test covers that case. The row counts and the tracing callback are kept, and calling close() twice is safe. The new tests cover closing after a partial read, using with break, throw and generators, a failed step, and statement-cache reuse.
⚡ Performance: ✅ LGTM
close() resets the statement sooner and adds no per-row work.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 12685c73
12685c7 to
669c202
Compare
There was a problem hiding this comment.
Superseded by the review of
8d5c9824.
This review, of 669c2023
✅ Approved — The opt-in API addition is correct and well tested, and the generated types match the source annotations. No issues were found.
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.d.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
Cursor::close() calls endQuery() whenever state is set. It is idempotent and safe after a failed step, and it throws when called from another Durable Object, as the cursor's other methods do. JSG_METHOD(close) and JSG_DISPOSE(close) are wired up correctly. The tests cover the partial-read, using, failed-step, statement-cache and cross-Durable-Object cases.
⚡ Performance: ✅ LGTM
close() resets the statement sooner and adds no per-row work.
📝 Documentation: ✅ LGTM
The updated comment in iteratorImpl describes the current behaviour. The generated type snapshots match the source annotations.
Reviewed commit: 669c2023
669c202 to
8d5c982
Compare
There was a problem hiding this comment.
Superseded by the review of
ca43afb9.
This review, of 8d5c9824
✅ Approved — Since the last review, close() throws from the wrong Durable Object and asserts that the statement state is cleared. Both are correct and tested, and no issues were found.
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.d.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
Cursor::close() now calls endQuery(*s) and then KJ_DASSERT(state == kj::none). Dereferencing the IoOwn throws when the call comes from another Durable Object, and closeOtherCursor tests that case. endQuery clears state, so the assertion holds. Leaving columnNames for garbage collection was already agreed in the discussion.
⚡ Performance: ✅ LGTM
close() resets the statement sooner and adds no per-row work.
📝 Documentation: ✅ LGTM
The updated iteratorImpl comment describes the current behaviour, and the generated type snapshots match the source annotations.
Reviewed commit: 8d5c9824
8d5c982 to
ca43afb
Compare
There was a problem hiding this comment.
Superseded by the review of
ba1cf2d2.
This review, of ca43afb9
✅ Approved — No issues found: close() correctly ends the query, is idempotent, throws from the wrong Durable Object, and is fully tested; types match the source annotations.
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.d.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Calling from another Durable Object throws when the IoOwn is dereferenced. The change adds no injection, authorization or data-exposure risk.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
close() ends an active query through endQuery, does nothing on a cursor with no active query, and never steps the statement. The tests cover partial iteration, using with break, throw and generators, calling close more than once, row counts and column names kept after close, statement reuse, wrong-Durable-Object calls and SuppressedError. The tail span counts match the new calls.
⚡ Performance: ✅ LGTM
close() releases the statement sooner and adds no per-row work.
📝 Documentation: ✅ LGTM
The updated iteratorImpl comment describes the current behaviour. All four generated type snapshots match the source annotations.
Reviewed commit: ca43afb9
ca43afb to
ba1cf2d
Compare
There was a problem hiding this comment.
Superseded by the review of
6bf27f03.
This review, of ba1cf2d2
✅ Approved — No issues found: close() correctly ends the query, is idempotent, throws from the wrong Durable Object, and is fully tested; types match the source annotations.
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.d.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Calling from another Durable Object throws when the IoOwn is dereferenced. The change adds no injection, authorization or data-exposure risk.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
close() ends an active query through endQuery, does nothing on a cursor with no active query, and never steps the statement. The tests cover partial iteration, using with break, throw and generators, calling close more than once, row counts and column names kept after close, statement reuse, wrong-Durable-Object calls and SuppressedError. The tail span counts match the new calls.
⚡ Performance: ✅ LGTM
close() releases the statement sooner and adds no per-row work.
📝 Documentation: ✅ LGTM
The updated iteratorImpl comment describes the current behaviour. All four generated type snapshots match the source annotations.
Reviewed commit: ba1cf2d2 — same changes as ca43afb9, so this is that commit's review (no new review was run; line numbers are as of ca43afb9)
|
The generated output of |
A cursor resets its SQLite statement only when it reaches its last row or when V8 collects it. An application that stops reading part way leaves the statement active on the Durable Object's connection, and while it is, SQLite rejects every DROP TABLE and DROP INDEX with SQLITE_LOCKED. The only way out was to call one() and ignore its error, which steps the statement once more: after a step has failed, that runs the statement again from the start. close() ends the query without stepping it: it resets the statement, returns it to the statement cache and keeps rowsRead, rowsWritten and columnNames. A closed cursor reads as one that has run to its end. close() is idempotent. Like the cursor's other methods, it throws when called from a Durable Object other than the one that created the cursor; under `using`, that error arrives as a SuppressedError that still carries the original one. JSG_DISPOSE(close) makes the cursor work with `using`, so that leaving the block by break, return, throw or a generator's return() closes it. Both are opt in, so existing code is unaffected.
ba1cf2d to
6bf27f0
Compare
There was a problem hiding this comment.
✅ Approved — No issues found: close() correctly ends the query, is idempotent, throws from the wrong Durable Object, and is fully tested; types match the source annotations.
Not opened by the correctness review: 2 changed files it was meant to read
types/generated-snapshot/experimental/index.tstypes/generated-snapshot/index.d.ts
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Calling from another Durable Object throws when the IoOwn is dereferenced. The change adds no injection, authorization or data-exposure risk.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
close() ends an active query through endQuery, does nothing on a cursor with no active query, and never steps the statement. The tests cover partial iteration, using with break, throw and generators, calling close more than once, row counts and column names kept after close, statement reuse, wrong-Durable-Object calls and SuppressedError. The tail span counts match the new calls.
⚡ Performance: ✅ LGTM
close() releases the statement sooner and adds no per-row work.
📝 Documentation: ✅ LGTM
The updated iteratorImpl comment describes the current behaviour. All four generated type snapshots match the source annotations.
Reviewed commit: 6bf27f03 — same changes as ca43afb9, so this is that commit's review (no new review was run; line numbers are as of ca43afb9)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8692 +/- ##
==========================================
- Coverage 68.01% 67.73% -0.28%
==========================================
Files 846 846
Lines 219198 215006 -4192
Branches 32587 32591 +4
==========================================
- Hits 149081 145635 -3446
+ Misses 50876 50128 -748
- Partials 19241 19243 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A SQL cursor resets its SQLite statement only when it reaches its last row or when V8 collects it. An application that stops reading part way leaves the statement active on the Durable Object's connection, and while it is, SQLite rejects every
DROP TABLEandDROP INDEXwithSQLITE_LOCKED.This adds
cursor.close(), which ends the query without stepping it, and[Symbol.dispose]()(viaJSG_DISPOSE(close)), so a cursor declared withusingis closed however its block exits:columnNames,rowsReadandrowsWrittenare kept.close()is idempotent and does not step the statement, so it is safe after a step failed. Like the cursor's other methods, it throws when called from a different Durable Object; underusing, that error arrives as aSuppressedErrorthat still carries the original one.close(): void, andSqlStorageCursorextendsDisposable, so TypeScript before 5.2 still compiles.