Skip to content

Conversation

@dicej
Copy link
Contributor

@dicej dicej commented Jan 8, 2026

Previously, we weren't updating or checking the may-block status of a task across sync-to-sync, guest-to-guest calls, meaning we were allowing blocking in cases we shouldn't have.

This fixes that by adding a new task_may_block field to VMComponentContext, plus code to update it every time we switch threads or do a sync-to-sync, guest-to-guest call. We use that field as the source of truth about whether a blocking operation is permitted.

I've updated various tests to match, and Luke has an item on his to-do list to add sad-path coverage for various cases to the upstream component-model test suite.

@dicej dicej marked this pull request as ready for review January 8, 2026 00:21
@dicej dicej requested review from a team as code owners January 8, 2026 00:21
@dicej dicej requested review from alexcrichton and removed request for a team January 8, 2026 00:21
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jan 8, 2026
Previously, we weren't updating or checking the may-block status of a task
across sync-to-sync, guest-to-guest calls, meaning we were allowing blocking in
cases we shouldn't have.

This fixes that by adding a new `task_may_block` field to `VMComponentContext`,
plus code to update it every time we switch threads or do a sync-to-sync,
guest-to-guest call.  We use that field as the source of truth about whether a
blocking operation is permitted.

I've updated various tests to match, and Luke has an item on his to-do list to
add sad-path coverage for various cases to the upstream `component-model` test
suite.
@dicej dicej force-pushed the better-may-block-tracking branch from 4954f10 to a64f444 Compare January 8, 2026 03:29
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Test-wise, to confirm, you feel that the upstream spec tests adequately cover this? And/or the test updates that were required here? Or should some dedicated tests be written as well?

Comment on lines 1156 to 1174
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct TaskMayBlock(SendSyncPtr<VMGlobalDefinition>);

impl TaskMayBlock {
pub unsafe fn get(&self) -> bool {
unsafe { *self.as_raw().as_ref().as_i32() != 0 }
}

pub unsafe fn set(&mut self, val: bool) {
unsafe {
*self.as_raw().as_mut().as_i32_mut() = if val { 1 } else { 0 };
}
}

pub fn as_raw(&self) -> NonNull<VMGlobalDefinition> {
self.0.as_non_null()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The old InstanceFlags structure is pretty unsafe due to retaining a long-lived pointer disconnected from the ComponentInstance, so ideally we wouldn't model this after that if we don't need to. Would it be possible to have safe get/set/as_raw methods on ComponentInstance and avoid having this type entirely?

@dicej dicej force-pushed the better-may-block-tracking branch from 437e308 to 3bc1908 Compare January 8, 2026 20:02
@dicej dicej force-pushed the better-may-block-tracking branch from cdc79e1 to b1d92e1 Compare January 8, 2026 20:34
@dicej dicej added this pull request to the merge queue Jan 8, 2026
Merged via the queue into bytecodealliance:main with commit fae9e6a Jan 8, 2026
45 checks passed
@dicej dicej deleted the better-may-block-tracking branch January 8, 2026 22:40
@dicej
Copy link
Contributor Author

dicej commented Jan 9, 2026

Test-wise, to confirm, you feel that the upstream spec tests adequately cover this? And/or the test updates that were required here? Or should some dedicated tests be written as well?

(Sorry, I forgot to respond to this earlier)

We do need dedicated tests for this, and I've added an item to @lukewagner's "WAST-as-a-service" backlog to cover that.

@alexcrichton
Copy link
Member

Makes sense, but while that makes sense for retroactively testing things I'd prefer to try to ensure that we are also writing *.wast tests for new things or anything our vision is currently set on. I don't think, for example, that Luke should be the one-and-only person writing those *.wast tests

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.

2 participants