Skip to content

Fix cancellation order between pipelines and tasks in CancelTasks#21642

Merged
Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
carlopi:fix_cancellation_order
Mar 27, 2026
Merged

Fix cancellation order between pipelines and tasks in CancelTasks#21642
Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
carlopi:fix_cancellation_order

Conversation

@carlopi
Copy link
Copy Markdown
Member

@carlopi carlopi commented Mar 26, 2026

Wrong order in CancelTasks I can't repro causing issues in current duckdb state, but it does become a problem by introducing more complex task logic, where I did found a bunch of problems that were tied to this.

@carlopi
Copy link
Copy Markdown
Member Author

carlopi commented Mar 26, 2026

I think this fixes duckdb/duckdb-ui#12, reproduction it's not super tight, but point at this direction.
(what I did was: build v1.5.1 on my laptop, reproduce issue, then cherry-pick commit, git reset HEAD~, rebuild, try to reproduce)

Other potentially related issues that might be (or not) connected to this fix are:
duckdb/pg_duckdb#974 (cancellation while COPY is in flight)
#16553

And, although it might be a stretch:
duckdb/duckdb-node-neo#151
#13904

Copy link
Copy Markdown
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Actually looking at this I think this changeset is wrong - the current destruction order is correct. Note that everything that is cleared is vectors holding shared pointers (e.g. shared_ptr<Event>). We have weak_ptr<Pipeline> elsewhere that we use to check if pipelines / events have been destroyed.

I'm guessing the actual problem is that somewhere there's an Event & or Pipeline & without correct ownership.

Currently this seems to break interruption (as indicated by the timeouts in CI).

Edit: I stand correct - I was thinking of this but that is old code that has been removed since. This might indeed be the correct solution (and we should then probably move back to having pipelines be unique_ptr<Pipeline> that live in the executor).

CancelTasks was destroying pipelines/events/states while tasks still held
references to them. Fix: set cancelled=true and drain all tasks first, then destroy pipelines.
@carlopi carlopi force-pushed the fix_cancellation_order branch from d5eb4fa to a80364e Compare March 26, 2026 15:48
@carlopi carlopi marked this pull request as draft March 26, 2026 16:22
@carlopi carlopi marked this pull request as ready for review March 26, 2026 16:25
@carlopi carlopi force-pushed the fix_cancellation_order branch from a80364e to c2ac5a9 Compare March 26, 2026 16:42
@carlopi carlopi marked this pull request as draft March 26, 2026 16:57
@carlopi carlopi marked this pull request as ready for review March 26, 2026 16:57
@Mytherin
Copy link
Copy Markdown
Collaborator

Thanks - I think this is good to go. We might want to look at lifetimes of the tasks referencing pipelines when the executor is destroyed separately.

@Mytherin Mytherin merged commit 57ad923 into duckdb:v1.5-variegata Mar 27, 2026
72 checks passed
@carlopi carlopi deleted the fix_cancellation_order branch March 27, 2026 09:15
github-actions Bot pushed a commit to krlmlr/duckdb-r that referenced this pull request Mar 27, 2026
Date: 2026-03-27 10:01:03 +0100

Fix cancellation order between pipelines and tasks in CancelTasks (duckdb/duckdb#21642)
bump delta and unity_catalog ext refs in v1.5-variegata (duckdb/duckdb#21640)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants