Skip to content

fix(drivers): a Stop that lands while a DuckDB, MongoDB, Cassandra, DynamoDB or Snowflake statement waits keeps it from running - #4761

Merged
datlechin merged 3 commits into
mainfrom
fix/registry-drivers-stop-before-start
Nov 30, 2026
Merged

datlechin merged 3 commits into
mainfrom
fix/registry-drivers-stop-before-start

Conversation

@datlechin

@datlechin datlechin commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • DuckDB: a user statement checks for Stop once its turn on the connection actor comes. duckdb_interrupt reaches only a running query and DuckDB clears it when the next one starts, so a Stop during the wait was lost. execute(query:) takes no check: host cleanup after a Stop goes through it.
  • MongoDB: a user statement takes a ticket (PluginStatementTickets) and the engine queue admits it right after beginStatement. That call clears the latch a Stop sets, so a Stop that landed while the statement waited for the engine was wiped and the statement ran, writes included. cancelQuery() now runs the runtime's cancel under the ticket stop. execute(query:) takes no ticket, and neither does a user's SELECT 1, which a ping answers.
  • Cassandra: executeParameterized (also executeUserQuery with parameters) begins its cancellation before the wait for the connection actor and passes it down, as execute already did.
  • DynamoDB: a request checks for Stop after it fetches credentials, which can take a round trip to STS or SSO.
  • Snowflake: a user statement (executeUserQuery, executeParameterized, the streamed capped read) checks for Stop before every send, the re-send after a session renewal included. A Stop during a renewal aborted a request the server had already refused, and the renewal then sent it again. A Stop marks the requests it can mean, and a marked request is never sent again. The host's cleanup sent from the task the Stop cancelled, such as its ROLLBACK, is not marked and a late cancelQuery() no longer aborts it. A ROLLBACK the host shields from cancellation can still be aborted by a late cancelQuery(), as on main; the kit 48 PR closes that.
  • The iOS app compiles PluginStatementTickets.swift for the MongoDB driver; its nested types are marked nonisolated.
  • Checked and left alone: BigQuery and Etcd never start a request a Stop came before. Trino checks right before its send. Cloudflare D1, LibSQL (remote) and Qdrant have no wait before the request; a task cancelled before data(for:) still sends, which a shared cancel-before-resume helper would close.

Test plan

  • MongoScriptStopTests (new, iOS): a statement whose ticket a Stop covered never runs on the engine, and one that takes its ticket after the Stop runs.
  • DuckDBStopBeforeStatementTests (new, iOS, in-memory DuckDB): a user statement and a parameterized one from a cancelled task change nothing; execute(query:) still runs.
  • MongoScriptHostPolicyTests passes the new admit argument.
  • Cassandra, DynamoDB and Snowflake are registry-only drivers with no test target (.claude/rules/tests.md); AllPlugins compiles them.
  • verify.sh ios on the branch that stacks this PR with the other Stop PRs: MongoScriptStopTests, DuckDBStopBeforeStatementTests, MongoScriptHostPolicyTests, CloudflareD1OnIOSTests, DataBrowserViewModelTests, 95 of 95.
  • After merging main in: verify.sh plugins (AllPlugins compiles every registry driver): PASS; verify.sh ios MongoScriptStopTests DuckDBStopBeforeStatementTests MongoScriptHostPolicyTests: 14 of 14. verify.sh lint on each changed Swift file: PASS.
  • Codex review, read-only, 3 rounds. Fixed from them: Snowflake re-sending a user statement after a renewal and holding back cleanup; MongoDB's iOS policy tests missing the new argument; a user SELECT 1 taking a ticket it never spent; a late cancelQuery() aborting cleanup sent after the Stop. The last round's remaining finding, a ROLLBACK the host shields from the Stop, closes with the kit 48 PR, where Snowflake aborts only the statements the host marks.

Uses the shared ticket type from #4758.

@datlechin
datlechin force-pushed the fix/registry-drivers-stop-before-start branch from a439a4b to a19d490 Compare November 30, 2026 06:06
@datlechin
datlechin changed the base branch from fix/mysql-stop-before-register to main November 30, 2026 06:08
…stop-before-start

# Conflicts:
#	apple/Plugins/Shared/PluginStatementTickets.swift
@datlechin
datlechin merged commit b1083e2 into main Nov 30, 2026
1 of 2 checks passed
@datlechin

datlechin commented Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Correction to the review line: the shielded ROLLBACK a late cancelQuery() could abort is fixed in #4778, not by narrowing aborts to marked statements (that would stop Stop from aborting Database Search). There the host marks its cleanup, and Snowflake never aborts commitTransaction(), rollbackTransaction() or a statement marked isHostCleanup.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant