A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
clean up subtask in `starting` state in `subtask_cancel` (#12322)
Joel Dicefd03e30b6d24
diff --git a/crates/misc/component-async-tests/tests/scenario/transmit.rs b/crates/misc/component-async-tests/tests/scenario/transmit.rsindex dc1f09f2b8..57ca2a4a05 100644--- a/crates/misc/component-async-tests/tests/scenario/transmit.rs+++ b/crates/misc/component-async-tests/tests/scenario/transmit.rs@@ -403,7 +403,7 @@ mod cancel {wasmtime::component::bindgen!({path: "wit",world: "cancel-host",- exports: { default: async | store },+ exports: { default: async | store | task_exit },});}@@ -500,10 +500,12 @@ async fn test_cancel(mode: Mode) -> Result<()> {cancel::CancelHost::instantiate_async(&mut store, &component, &linker).await?;store.run_concurrent(async move |accessor| {- cancel_host+ let ((), task) = cancel_host.local_local_cancel().call_run(accessor, mode, delay_millis())- .await+ .await?;+ task.block(accessor).await;+ Ok::<_, wasmtime::Error>(())}).await??;diff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rsindex 7df5c07dd8..2ad06ef271 100644--- a/crates/wasmtime/src/runtime/component/concurrent.rs+++ b/crates/wasmtime/src/runtime/component/concurrent.rs@@ -3477,11 +3477,22 @@ impl Instance {let guest_task = TableId::<GuestTask>::new(rep);let task = concurrent_state.get_mut(guest_task)?;if !task.already_lowered_parameters() {+ // The task is in a `starting` state, meaning it hasn't run at+ // all yet. Here we update its fields to indicate that it is+ // ready to delete immediately once `subtask.drop` is called.task.lower_params = None;task.lift_result = None;+ task.exited = true;- // Not yet started; cancel and remove from pendinglet instance = task.instance;++ assert_eq!(1, task.threads.len());+ let thread = mem::take(&mut task.threads).into_iter().next().unwrap();+ let concurrent_state = store.concurrent_state_mut();+ concurrent_state.delete(thread)?;+ assert!(concurrent_state.get_mut(guest_task)?.ready_to_delete());++ // Not yet started; cancel and remove from pendinglet pending = &mut store.instance_state(instance).pending;let pending_count = pending.len();pending.retain(|thread, _| thread.task != guest_task);