Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

trap if `task.cancel` called before cancel event delivered (#14378)

Joel Diceff7896b6d97a
diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rs
index ca3102aa3a..f328795cb9 100644
--- a/crates/test-util/src/wast.rs
+++ b/crates/test-util/src/wast.rs
@@ -694,6 +694,20 @@ impl WastTest {
return true;
}
+ // `stream.forward` not yet implemented:
+ let uses_stream_forward = [
+ "component-model/test/values/post-return.wast",
+ "component-model/test/async/big-interleaving-test.wast",
+ "component-model/test/async/forward.wast",
+ ];
+
+ if uses_stream_forward
+ .iter()
+ .any(|part| self.path.ends_with(part))
+ {
+ return true;
+ }
+
false
}
}
diff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rs
index 66fe1be36d..ea5851f970 100644
--- a/crates/wasmtime/src/runtime/component/concurrent.rs
+++ b/crates/wasmtime/src/runtime/component/concurrent.rs
@@ -2553,11 +2553,17 @@ impl Instance {
) -> Result<Option<(Event, Option<(Waitable, u32)>)>> {
let state = store.concurrent_state_mut()?;
- let event = &mut state.get_mut(guest_task)?.event;
+ let task = state.get_mut(guest_task)?;
+ let event = &mut task.event;
if let Some(ev) = event
&& (cancellable || !matches!(ev, Event::Cancelled))
{
log::trace!("deliver event {ev:?} to {guest_task:?}");
+
+ if matches!(ev, Event::Cancelled) {
+ task.cancel_request_delivered = true;
+ }
+
let ev = *ev;
*event = None;
return Ok(Some((ev, None)));
@@ -3610,7 +3616,7 @@ impl Instance {
let guest_thread = store.current_guest_thread()?;
let state = store.concurrent_state_mut()?;
let task = state.get_mut(guest_thread.task)?;
- if !task.cancel_sent {
+ if !task.cancel_request_delivered {
bail!(Trap::TaskCancelNotCancelled);
}
_ = task
@@ -4245,7 +4251,7 @@ impl Instance {
} else if !task.returned_or_cancelled() {
// Started, but not yet returned or cancelled; send the
// `CANCELLED` event
- task.cancel_sent = true;
+ //
// Note that this might overwrite an event that was set earlier
// (e.g. `Event::None` if the task is yielding, or
// `Event::Cancelled` if it was already cancelled), but that's
@@ -5148,9 +5154,10 @@ pub(crate) struct GuestTask {
/// A place to stash the lowered result for a sync-to-async call until it
/// can be returned to the caller.
sync_result: SyncResult,
- /// Whether or not the task has been cancelled (i.e. whether the task is
- /// permitted to call `task.cancel`).
- cancel_sent: bool,
+ /// Whether or not the task has been cancelled (i.e. whether the
+ /// cancellation request has been delivered to the task, and thus whether
+ /// the task is permitted to call `task.cancel`).
+ cancel_request_delivered: bool,
/// Whether or not we've sent a `Status::Starting` event to any current or
/// future waiters for this waitable.
starting_sent: bool,
@@ -5248,7 +5255,7 @@ impl GuestTask {
caller,
call_context: CallContext::default(),
sync_result: SyncResult::NotProduced,
- cancel_sent: false,
+ cancel_request_delivered: false,
starting_sent: false,
instance,
event: None,
diff --git a/tests/component-model b/tests/component-model
index 07afb8145b..5b724da8c6 160000
--- a/tests/component-model
+++ b/tests/component-model
@@ -1 +1 @@
-Subproject commit 07afb8145b80de8421256ac1648017c4bd67b136
+Subproject commit 5b724da8c634c4f2b2d2b3f6a4e9e13b4eb01596