A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
concurrency tweaks to match recent spec changes (#14250)
Joel Dicef6b3140dbb1d
diff --git a/crates/test-programs/src/bin/async_cancel_caller.rs b/crates/test-programs/src/bin/async_cancel_caller.rsindex 057cb1a067..7ca3692c11 100644--- a/crates/test-programs/src/bin/async_cancel_caller.rs+++ b/crates/test-programs/src/bin/async_cancel_caller.rs@@ -284,13 +284,14 @@ unsafe extern "C" fn callback_run(event0: u32, event1: u32, event2: u32) -> u32assert_eq!(event1, *waitable);assert_eq!(event2, STATUS_RETURNED);+ waitable_join(*waitable, 0);+if *mode == MODE_TRAP_CANCEL_GUEST_AFTER_RETURN {// This should trap, since `waitable` has already returned:subtask_cancel_async(*waitable);unreachable!()}- waitable_join(*waitable, 0);subtask_drop(*waitable);// Next, call and cancel `yield_with_options::yield_times` withdiff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rsindex 79be3eb1b8..ce8e46eb64 100644--- a/crates/wasmtime/src/runtime/component/concurrent.rs+++ b/crates/wasmtime/src/runtime/component/concurrent.rs@@ -3914,6 +3914,12 @@ impl Instance {GuestThread::from_instance(self.id().get_mut(store), runtime_instance, thread_idx)?;let state = store.concurrent_state_mut()?;let guest_thread = QualifiedThreadId::qualify(state, thread_id)?;++ if store.current_guest_thread()? == guest_thread {+ bail!(Trap::CannotResumeThread);+ }++ let state = store.concurrent_state_mut()?;let thread = state.get_mut(guest_thread.thread)?;let priority = match how {ResumeThread::Promote | ResumeThread::Resume => Priority::Switch,@@ -4172,9 +4178,7 @@ impl Instance {log::trace!("subtask_cancel {waitable:?} (handle {task_id}; async {async_})");- if !async_ {- waitable.trap_if_in_waitable_set(concurrent_state)?;- }+ waitable.trap_if_in_waitable_set(concurrent_state)?;let needs_block;if let Waitable::Host(host_task) = waitable {@@ -4978,6 +4982,22 @@ enum GuestThreadState {Completed,}+impl fmt::Debug for GuestThreadState {+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {+ match self {+ Self::NotStartedImplicit => f.debug_tuple("NotStartedImplicit").finish(),+ Self::NotStartedExplicit(_) => f.debug_tuple("NotStartedExplicit").finish(),+ Self::Running => f.debug_tuple("Running").finish(),+ Self::Suspended(_) => f.debug_tuple("Suspended").finish(),+ Self::Ready { cancellable, .. } => f+ .debug_struct("Ready")+ .field("cancellable", cancellable)+ .finish(),+ Self::Completed => f.debug_tuple("Completed").finish(),+ }+ }+}+pub struct GuestThread {/// Context-local state used to implement the `context.{get,set}`/// intrinsics.diff --git a/tests/component-model b/tests/component-modelindex 2f1326540f..cfc02668ce 160000--- a/tests/component-model+++ b/tests/component-model@@ -1 +1 @@-Subproject commit 2f1326540f73f8d58237028f8331c048b3e44d76+Subproject commit cfc02668ce804e64ed542938e95b3322eecc346f