Skip to content

fix over-eager deletion of task groups on trap - #14555

Merged
dicej merged 1 commit into
bytecodealliance:mainfrom
dicej:fix-14504
Oct 10, 2026
Merged

dicej merged 1 commit into
bytecodealliance:mainfrom
dicej:fix-14504

Conversation

@dicej

@dicej dicej commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Instead of deleting any outstanding task groups when trapping, we now just record that we've notified the task hook so we don't do it again if and when the group's ref count goes to zero.

Fixes #14504

@dicej
dicej requested a review from alexcrichton October 5, 2026 21:54
@dicej
dicej requested a review from a team as a code owner October 5, 2026 21:54

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit confused by how this works -- the finished field is never set to true while the groups are in the table, except when the store is torn down. Was this a problem where during teardown the same group was deleted twice? If so could that be solved by reordering some teardown?

Comment thread tests/all/component_model/async.rs Outdated
@dicej

dicej commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

I'm a bit confused by how this works -- the finished field is never set to true while the groups are in the table, except when the store is torn down. Was this a problem where during teardown the same group was deleted twice? If so could that be solved by reordering some teardown?

clean_up_task_groups is called in two places: when a store is poisoned due to a trap and when it is disposed. In either case, the may be other cleanup after that call completes (e.g. gracefully disposing of fibers, etc.) which may cause guest and/or host tasks to be disposed, in which case we may try to look up the task group for those tasks to dispose it, but since clean_up_task_groups had already deleted the group, we errored, and that error was escalated to a panic in SignalOnDrop::drop.

@alexcrichton

Copy link
Copy Markdown
Member

Do we need to run this on set_trapped? Would it be possible to only run this on store teardown?

@github-actions github-actions Bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Oct 6, 2026
@dicej

dicej commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Do we need to run this on set_trapped? Would it be possible to only run this on store teardown?

No, we don't have to; I figured it would be best to do it promptly, but I'd be fine with only doing it on store teardown. And note that we'd have to make sure it's pretty much the last thing we do on store teardown if we want to delete any task groups before their reference counts go to zero; otherwise, we'll risk hitting this issue again.

@alexcrichton

Copy link
Copy Markdown
Member

I think that'd be best to implement yeah, I found it pretty surprising that set_trapped also had a side effect of running arbitrary embedder code

@dicej

dicej commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@alexcrichton I've applied your feedback and rebased onto main.

We now delay deleting the task groups until all fibers have been disposed, and
we no longer do so immediately upon trapping.  This ensures that no code will
run later that might get tripped up on prematurely-deleted (i.e. deleted before
the refcount goes to zero) groups.

Fixes bytecodealliance#14504

Co-Authored-By: Alex Crichton <alex@alexcrichton.com>
@dicej
dicej enabled auto-merge October 9, 2026 22:21
@dicej
dicej added this pull request to the merge queue Oct 9, 2026
Merged via the queue into bytecodealliance:main with commit 28313ae Oct 10, 2026
53 checks passed
@dicej
dicej deleted the fix-14504 branch October 10, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task-group-hook cleanup is too eager, leading to a host panic

2 participants