Skip to content

Conversation

@dicej
Copy link
Contributor

@dicej dicej commented Nov 18, 2025

This implements a spec change (PR pending) such that tasks created for calls to synchronous exports may not call potentially-blocking imports or return wait or poll callback codes prior to returning a value. Specifically, the following are prohibited in that scenario:

  • returning callback-code.{wait,poll}
  • sync calling an async import
  • sync calling subtask.cancel
  • sync calling {stream,future}.{read,write}
  • sync calling {stream,future}.cancel-{read,write}
  • calling waitable-set.{wait,poll}
  • calling thread.suspend

This breaks a number of tests, which will be addressed in follow-up commits:

  • The {tcp,udp}-socket.bind implementation in wasmtime-wasi is implemented using Linker::func_wrap_concurrent and thus assumed to be async, whereas the WIT interface says they're sync, leading to a type mismatch error at runtime. Alex and I have discussed this and have a general plan to address it.

  • A number of tests in the tests/component-model submodule that points to the spec repo are failing. Those will presumably be fixed as part of the upcoming spec PR (although some could be due to bugs in this implementation, in which case I'll fix them).

  • A number of tests in tests/misc_testsuite are failing. I'll address those in a follow-up commit.

@dicej dicej requested a review from alexcrichton November 18, 2025 18:30
This implements a spec change (PR pending) such that tasks created for calls to
synchronous exports may not call potentially-blocking imports or return `wait`
or `poll` callback codes prior to returning a value.  Specifically, the
following are prohibited in that scenario:

- returning callback-code.{wait,poll}
- sync calling an async import
- sync calling subtask.cancel
- sync calling {stream,future}.{read,write}
- sync calling {stream,future}.cancel-{read,write}
- calling waitable-set.{wait,poll}
- calling thread.suspend

This breaks a number of tests, which will be addressed in follow-up commits:

- The `{tcp,udp}-socket.bind` implementation in `wasmtime-wasi` is implemented
  using `Linker::func_wrap_concurrent` and thus assumed to be async, whereas the
  WIT interface says they're sync, leading to a type mismatch error at runtime.
  Alex and I have discussed this and have a general plan to address it.

- A number of tests in the tests/component-model submodule that points to the
  spec repo are failing.  Those will presumably be fixed as part of the upcoming
  spec PR (although some could be due to bugs in this implementation, in which
  case I'll fix them).

- A number of tests in tests/misc_testsuite are failing.  I'll address those in
  a follow-up commit.

Signed-off-by: Joel Dice <[email protected]>
@dicej dicej force-pushed the trap-blocking-in-sync-tasks branch from c6c26c4 to 3547452 Compare November 18, 2025 18:33
`check_blocking` needs access to the current task, but that's not set for
post-return functions since those should not be calling _any_ imports at all, so
first check for that.

Signed-off-by: Joel Dice <[email protected]>
This amounts to adding `async` to any exported component functions that might
need to block.

Signed-off-by: Joel Dice <[email protected]>
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Nov 18, 2025
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.

1 participant