Skip to content

rust: block_on panics if the future yields before any waitable is registered #1718

Description

@dsamp

This code:

fn main() {
    wit_bindgen::block_on(async {
        wit_bindgen::yield_async().await;
    });
    println!("done");
}

currently panics with the following message:

thread 'main' (1) panicked at .../wit-bindgen-0.62.0/src/rt/async_support.rs:671:38:
called Option::unwrap() on a None value

It isn't specific to yield_async. Any wake that happens while the task set is being polled, before the first host call, hits it too. Putting a host call first avoids it, e.g. awaiting wasip3::clocks::monotonic_clock::wait_for(1_000_000). After that, the same yields work.

This is because SharedTaskState::waitable_set starts as None and is only created in add_waitable. The waitable set is unwrapped unconditionally:

CallbackCode::Yield => {
    let set = state.shared.waitable_set.try_lock().unwrap();
    event = set.as_ref().unwrap().poll()
}

I don't know if there is a good rational for this, but perhaps the waitable_set should not be an Option or the arm should return (EVENT_NONE, 0, 0) instead of unwrapping.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions