Skip to content

Fix/improve host subtask cancellation#12640

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:fix-host-subtask-canel
Feb 23, 2026
Merged

Fix/improve host subtask cancellation#12640
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:fix-host-subtask-canel

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton commented Feb 23, 2026

This commit refactors some of the internals of subtask.cancel with respect to host subtasks. Notably a few panics and semantic bugs are fixed here. The main bug was that host subtasks could be aborted but their completion might have still been queued up which would produce the result somewhere or assert that the task exists. Cancellation is changed to use wait_for_event to ensure that this completion is executed before subtask.cancel returns. This helps keep host subtasks looking more similar to guest subtasks in that respect.

Closes #12631
Closes #12632

@alexcrichton alexcrichton requested a review from a team as a code owner February 23, 2026 17:58
@alexcrichton alexcrichton requested review from cfallin and removed request for a team February 23, 2026 17:58
This commit refactors some of the internals of `subtask.cancel` with
respect to host subtasks. Notably a few panics and semantic bugs are
fixed here. The main bug was that host subtasks could be aborted but
their completion might have still been queued up which would produce the
result somewhere or assert that the task exists. Cancellation is changed
to use `wait_for_event` to ensure that this completion is executed
before `subtask.cancel` returns. This helps keep host subtasks looking
more similar to guest subtasks in that respect.

Closes bytecodealliance#12631
Closes bytecodealliance#12632

Co-authored-by: Jelle van den Hooff <[email protected]>
@jellevandenhooff
Copy link
Copy Markdown
Contributor

thanks for the fast fix! I couldn’t quite tell from reading the code if this will change the subtask.cancel behavior: will a cancel in progress now require the caller to wait before dropping?

Copy link
Copy Markdown
Contributor

@dicej dicej left a comment

Choose a reason for hiding this comment

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

Thanks!

@alexcrichton
Copy link
Copy Markdown
Member Author

Spec-wise subtask.cancel stays the same, so no changes there. Wasmtime is changing a bit semantically though (within the allowable behaviors of the spec) where previously cancellation of a host subtask would never block, but now it blocks waiting for the cancellation notifcation to actually get received. That doesn't require any new behaviors in the guest, however, and it's only exposed if the guest is using the async option on subtask.cancel which it in theory would already be handling anyway.

@alexcrichton alexcrichton added this pull request to the merge queue Feb 23, 2026
@jellevandenhooff
Copy link
Copy Markdown
Contributor

Great, thanks. I was so far relying on cancel and then an immediate drop working, so I’ll have to become spec compliant in my guest. That is of course what the code should have done in the first place… but it will require some thinking because cancel+drop was a nice instantaneous cleanup path.

Merged via the queue into bytecodealliance:main with commit 065baac Feb 23, 2026
45 checks passed
@alexcrichton alexcrichton deleted the fix-host-subtask-canel branch February 23, 2026 18:58
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.

3 participants