Make cancelling a running query actually work #9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/cancel-running-query"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The toolbar Cancel button sent
EngineCommand::ResetSessioninto the command channel. The worker thread is blocked inrun_sqlwhile a query runs, so the command only ran after the query had finished. The UI marked the query as stopped, the full result still arrived later, and then the session was reset for nothing.Fix
RunningQuery { child, cancelled }.DuckDbClient::cancel_query()kills it from the UI thread, which unblocksrun_sql. Only a query that is actually running can be cancelled. Queries still waiting in the queue are unaffected.CANCELLED_MESSAGE, which says temp tables,SEToptions and:memory:data are lost, and that data committed to a database file is kept.run_sqldrops the partial chunk of the interrupted statement and keeps the results of statements that finished.ActiveProcess::is_alive).:cancel/:stop. Both buttons have a tooltip explaining the session restart.AGENTS.md.Testing
cargo testpasses (32 tests).test_cancel_long_running_query_keeps_finished_statementsruns against the real DuckDB CLI. It starts a minutes-long query after a quick statement, cancels it, and checks that the cancel finishes within 5s (about 0.3s in practice), thatCANCELLED_MESSAGEis reported, that the finished statement's result is kept, and that the next query runs in the new session. It passed 8 of 8 repeated runs.:cancel/:stopmapping.Child::killusesTerminateProcess. Not yet checked by hand in the Windows GUI.🤖 Generated with Claude Code