Skip to content

Leave the host call when a host import fails - #21

Draft
noise64 wants to merge 1 commit into
golem-wasmtime-v50.0.1-p3from
fix-host-call-error-cleanup
Draft

noise64 wants to merge 1 commit into
golem-wasmtime-v50.0.1-p3from
fix-host-call-error-cleanup

Conversation

@noise64

@noise64 noise64 commented Nov 26, 2026

Copy link
Copy Markdown

When a host import fails after host_task_create, the error now also leaves the host call. Before, call_sync_lower and call_async_lower returned with ? and did not call host_task_delete. With component-model-async, the current thread stayed DeferredHost(caller) and the deferred call and its call context stayed set. This happens for a host error such as I32Exit from wasi:cli/exit, and also for a guest error found while the parameters are lifted.

A Store that runs more host work after such a trap then fails debug_assert_deferred_host_invariant in set_thread ("a deferred host thread and call context must exist together"). Golem does this: after a tool calls wasi:cli/exit, the executor finishes the tool's output streams on the trapped Store with run_concurrent, which polls a host task that the guest left pending. This is golemcloud/golem#4617.

  • host_task_delete_after_error is the error dual of host_task_create. While the call is still a deferred host call, it makes the caller the current thread again and removes the deferred call and call context, as host_task_delete does. After host_task_delete, or after the call was materialized into a host task, it changes nothing. Without concurrency support it leaves the call scope, as host_task_delete does.
  • call_sync_lower and call_async_lower each split into an outer part, which enters the host task and leaves it on any error, and an *_entered part with the original body. The sync part records when it reaches host_task_delete, so that a call scope is never left twice.
  • failed_host_call_leaves_no_deferred_host_call covers a host error with sync and async lowering and a lift error with sync lowering. Each case polls the Store again after the trap.

Not changed: a host task that is materialized and then fails before the event loop or a subtask owns it (for example poll_and_block when the caller may not suspend) still stays in the table. That already happens on golem-wasmtime-v50.0.1-p3.

Local checks: cargo test -p wasmtime --tests, cargo clippy -p wasmtime --all-targets --features component-model-async, cargo check -p wasmtime --no-default-features --features component-model,runtime,cranelift,async, rustfmt. Not run here: tests/all and component-async-tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant