Skip to content

Allow wasi-http to return error to the caller instead of fail hard #10784

@xofyarg

Description

@xofyarg

Feature

Giving the following wasi-http design and implementation:

resource response-outparam {
   set: static func(
     param: response-outparam,
     response: result<outgoing-response, error-code>,
   );
}
fn set(
    &mut self,
    id: Resource<HostResponseOutparam>,
    resp: Result<Resource<HostOutgoingResponse>, types::ErrorCode>,
) -> wasmtime::Result<()> {
    let val = match resp {
        Ok(resp) => Ok(self.table().delete(resp)?.try_into()?),
        Err(e) => Err(e),
    };

    self.table()
        .delete(id)?
        .result
        .send(val)  <--- may fail the host call
        .map_err(|_| anyhow::anyhow!("failed to initialize response"))
}

The common scenario is a host is waiting for a response from the guest under a given timeout. If the timeout is reached without having anything from the guest, the host will drop the receiver side of the channel, which will fail the hostcall and likely crash the wasi program.

Benefit

The error doesn't seem to be fatal, and the caller should be able to decide what to do next.

Implementation

Maybe allow the set API to return an error to the caller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasi:apiIssues pertaining to the WASI API, not necessarily specific to Wasmtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions