Skip to content

wasi::http::outgoing_handler::handle crashes wasmtime instead of returning an error #8269

@kaivol

Description

@kaivol

Test Case

Call wasi::http::outgoing_handler::handle with an invalid argument (e.g., path_with_query not set):

use wasi::http::outgoing_handler::{handle, OutgoingRequest};
use wasi::http::types::{Fields, Method, Scheme};

fn main() {
    let fields = Fields::new();
    let req = OutgoingRequest::new(fields);
    req.set_method(&Method::Get).unwrap();
    req.set_scheme(Some(&Scheme::Https)).unwrap();
    req.set_authority(Some("example.com")).unwrap();
    // Don't set path/query
    // req.set_path_with_query(Some("/")).unwrap(); 

    let res = handle(req, None);
    println!("{res:?}");
}

Steps to Reproduce

  • Compile the example into a WASM component
  • Run using wasmtime -W component-model -S http=true

Expected Results

handle should return an error, which then gets printed by the WASM component.

Actual Results

handle crashes the wasmtime runtime immediately, and the component code doesn't get a chance to handle the error:

Error: failed to run main module `.\target\wasm32-wasi\debug\wasmtime_demo.wasm`

Caused by:
    0: failed to invoke `run` function
    1: error while executing at wasm backtrace:
           0: 0x291982 - wit-component:shim!indirect-wasi:http/outgoing-handler@0.2.0-handle
           1: 0x5c27 - <unknown>!wasi::bindings::wasi::http::outgoing_handler::handle::h243762d529a071e2
           2: 0x2287 - <unknown>!wasmtime_demo::main::h6a3dfdd89fcbbb62
           3: 0x1e9a - <unknown>!core::ops::function::FnOnce::call_once::hef7075ed4fc37c5f
           4: 0x18ff - <unknown>!std::sys_common::backtrace::__rust_begin_short_backtrace::ha7ad02d581d2e631
           5: 0x1878 - <unknown>!std::rt::lang_start::{{closure}}::h298ac82840374e7e
           6: 0xf239 - <unknown>!std::rt::lang_start_internal::h11043ae9961d0df9
           7: 0x1814 - <unknown>!std::rt::lang_start::ha68b6582d347d4c9
           8: 0x2384 - <unknown>!__main_void
           9: 0x16d6 - <unknown>!_start
          10: 0x28dae9 - wit-component:adapter:wasi_snapshot_preview1!wasi:cli/run@0.2.0#run
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    2: ErrorCode::HttpProtocolError

Versions and Environment

Wasmtime version or commit: 19.0.0

Operating system: Windows 11

Architecture: x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions