[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch Fix #1

Merged
merged 19 commits into from
May 20, 2024
Merged

Fetch Fix #1

merged 19 commits into from
May 20, 2024

Conversation

nicoburniske
Copy link
Owner
@nicoburniske nicoburniske commented Apr 30, 2024

Fixes trap when reading body from Fetch Response.

Old behavior RequestOrResponse::bodyAll

  1. Calls mark_body_used:

    • Calls streams::NativeStreamSource::lock_stream:
      • Creates ReadableStreamReader (which locks stream)
      • Stores ReadableStreamReader in Slots::InternalReader
  2. Calls consume_content_stream_for_bodyAll:

    • Checks that stream is not locked or disturbed (body_unusable)
      • Stream was locked in previous step, so this fails
    • Creates new ReadableStreamReader
      • ReadableStreamReader was already created in previous step

Revised behavior RequestOrResponse::bodyAll

  1. Calls mark_body_used:

    • Calls streams::NativeStreamSource::lock_stream:
      • Creates ReadableStreamReader (which locks stream)
      • Stores ReadableStreamReader in Slots::InternalReader
  2. Calls consume_content_stream_for_bodyAll:

    • Checks that stream is not locked or disturbed
      • No reason to check if stream is locked, because it was locked in previous step.
    • Extracts ReadableStreamReader from Slots::InternalReader

E2E Test cases

  • fetch-1
    • GET request with small json body
  • fetch-2
    • GET request with large body being read incrementally with ReadableStreamDefaultReader
  • fetch-3
    • POST request with large json body
  • fetch-4
    • POST request with async body stream
    • This one still fails

@@ -1141,7 +1149,11 @@ JSObject *RequestOrResponse::create_body_stream(JSContext *cx, JS::HandleObject
return nullptr;
}

// TODO: immediately lock the stream if the owner's body is already used.
// If the body has already been used without being reified as a ReadableStream,
// lock the stream immediately.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line cost me the entire day yesterday

Copy link
@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I would add more tests. We want to make sure fetch is as bulletproof as we can make it, for the different scenarios (text/json/etc., error / success, big / small, headers / no-headers).

@nicoburniske
Copy link
Owner Author
nicoburniske commented May 1, 2024

There's a bug in fetch-3 test. The bug only arises when the fetch request has a body.

The relevant error is unknown handle index 1. Error appears to come from accessing an invalid resource handle, which is supposed to correspond to the request http headers.

Observations

  • The error guest never invoked response-outparam::set method is misleading and not the relevant one. That is a side effect of running wasmtime serve. The component is trapping and then wasmtime serve never gets a response, and then is never calling response-outparam::set.
  • The pointer that's being stored in the slot is the same between creation/storage/retrieval 0x6175a0 and has a value of 1
  • Headers works normally, just not in the presence of a body.
  • Could the Headers object be dropped somewhere?
  • One thing to notice is that the wasi_http logs never show a Resource { rep: 1 , ... }. The smallest resource number is 2. This could potentially be the problem with the c bindings?

Run command

This test can be run individually with this command

WASMTIME_BACKTRACE_DETAILS=1 WASMTIME_LOG=wasmtime_wasi wasmtime serve -S common tests/e2e/fetch-3/fetch-3.wasm

Test case ouput

Serving HTTP on http://0.0.0.0:57478/
2024-05-01T15:42:33.190119Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.method"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 0, state: "borrow" }
2024-05-01T15:42:33.190159Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.method"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Method::Get)
2024-05-01T15:42:33.190198Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.scheme"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 0, state: "borrow" }
2024-05-01T15:42:33.190204Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.scheme"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Some(Scheme::Http))
2024-05-01T15:42:33.190212Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.authority"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 0, state: "borrow" }
2024-05-01T15:42:33.190216Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.authority"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Some("localhost:57478"))
2024-05-01T15:42:33.190254Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.path-with-query"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 0, state: "borrow" }
2024-05-01T15:42:33.190258Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]incoming-request.path-with-query"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Some("/"))
2024-05-01T15:42:33.190673Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: call
2024-05-01T15:42:33.190679Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: return result=Ok(1714333)
2024-05-01T15:42:33.190910Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: call
2024-05-01T15:42:33.190914Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: return result=Ok(1949583)
2024-05-01T15:42:33.190997Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: call
2024-05-01T15:42:33.191000Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: return result=Ok(2036167)
2024-05-01T15:42:33.191040Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: call
2024-05-01T15:42:33.191043Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: return result=Ok(2078667)
2024-05-01T15:42:33.191075Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: call
2024-05-01T15:42:33.191078Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="monotonic-clock" function="now"}: wasmtime_wasi::bindings::wasi::clocks::monotonic_clock: return result=Ok(2113542)
2024-05-01T15:42:33.191297Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[constructor]fields"}: wasmtime_wasi_http::bindings::wasi::http::types: call
2024-05-01T15:42:33.191302Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[constructor]fields"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Resource { rep: 2, state: "own (not in table)" })
2024-05-01T15:42:33.191333Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="stdin" function="get-stdin"}: wasmtime_wasi::bindings::wasi::cli::stdin: call
2024-05-01T15:42:33.191338Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="stdin" function="get-stdin"}: wasmtime_wasi::bindings::wasi::cli::stdin: return result=Ok(Resource { rep: 3, state: "own (not in table)" })
2024-05-01T15:42:33.191345Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="stdout" function="get-stdout"}: wasmtime_wasi::bindings::wasi::cli::stdout: call
2024-05-01T15:42:33.191348Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="stdout" function="get-stdout"}: wasmtime_wasi::bindings::wasi::cli::stdout: return result=Ok(Resource { rep: 4, state: "own (not in table)" })
2024-05-01T15:42:33.191355Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="stderr" function="get-stderr"}: wasmtime_wasi::bindings::wasi::cli::stderr: call
2024-05-01T15:42:33.191357Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="stderr" function="get-stderr"}: wasmtime_wasi::bindings::wasi::cli::stderr: return result=Ok(Resource { rep: 5, state: "own (not in table)" })
2024-05-01T15:42:33.191363Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="preopens" function="get-directories"}: wasmtime_wasi::bindings::wasi::filesystem::preopens: call
2024-05-01T15:42:33.191367Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="preopens" function="get-directories"}: wasmtime_wasi::bindings::wasi::filesystem::preopens: return result=Ok([])
2024-05-01T15:42:33.191382Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: call self_=Resource { rep: 5, state: "borrow" } contents=[67, 114, 101, 97, 116, 101, 100, 32, 72, 101, 97, 100, 101, 114, 32, 82, 101, 115, 111, 117, 114, 99, 101, 58, 32, 32, 48, 120, 54, 49, 55, 53, 97, 48, 32, 49, 10]
stderr [0] :: Created Header Resource:  0x6175a0 1
2024-05-01T15:42:33.191392Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: return result=Ok(())
2024-05-01T15:42:33.191424Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[constructor]outgoing-request"}: wasmtime_wasi_http::bindings::wasi::http::types: call headers=Resource { rep: 2, state: "own (not in table)" }
2024-05-01T15:42:33.191436Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[constructor]outgoing-request"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Resource { rep: 2, state: "own (not in table)" })
2024-05-01T15:42:33.191444Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-method"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 2, state: "borrow" } method=Method::Post
2024-05-01T15:42:33.191447Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-method"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Ok(()))
2024-05-01T15:42:33.191453Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-scheme"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 2, state: "borrow" } scheme=Some(Scheme::Https)
2024-05-01T15:42:33.191456Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-scheme"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Ok(()))
2024-05-01T15:42:33.191463Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-authority"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 2, state: "borrow" } authority=Some("echo.free.beeceptor.com")
2024-05-01T15:42:33.191468Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-authority"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Ok(()))
2024-05-01T15:42:33.191473Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-path-with-query"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 2, state: "borrow" } path_with_query=Some("/")
2024-05-01T15:42:33.191477Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.set-path-with-query"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Ok(()))
2024-05-01T15:42:33.191508Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.body"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 2, state: "borrow" }
2024-05-01T15:42:33.191512Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-request.body"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Ok(Resource { rep: 6, state: "own (not in table)" }))
2024-05-01T15:42:33.191520Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-body.write"}: wasmtime_wasi_http::bindings::wasi::http::types: call self_=Resource { rep: 6, state: "borrow" }
2024-05-01T15:42:33.191525Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="types" function="[method]outgoing-body.write"}: wasmtime_wasi_http::bindings::wasi::http::types: return result=Ok(Ok(Resource { rep: 7, state: "own (not in table)" }))
2024-05-01T15:42:33.191536Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.check-write"}: wasmtime_wasi::bindings::wasi::io::streams: call self_=Resource { rep: 7, state: "borrow" }
2024-05-01T15:42:33.191539Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.check-write"}: wasmtime_wasi::bindings::wasi::io::streams: return result=Ok(1048576)
2024-05-01T15:42:33.191547Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.write"}: wasmtime_wasi::bindings::wasi::io::streams: call self_=Resource { rep: 7, state: "borrow" } contents=[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
2024-05-01T15:42:33.191551Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.write"}: wasmtime_wasi::bindings::wasi::io::streams: return result=Ok(())
2024-05-01T15:42:33.191564Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: call self_=Resource { rep: 5, state: "borrow" } contents=[109, 97, 121, 98, 101, 95, 104, 101, 97, 100, 101, 114, 115, 32, 105, 115, 32, 110, 117, 108, 108, 10]
stderr [0] :: maybe_headers is null
2024-05-01T15:42:33.191570Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: return result=Ok(())
2024-05-01T15:42:33.191578Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: call self_=Resource { rep: 5, state: "borrow" } contents=[104, 101, 97, 100, 101, 114, 115, 73, 110, 115, 116, 97, 110, 99, 101, 32, 105, 115, 32, 78, 79, 84, 32, 110, 117, 108, 108, 10]
stderr [0] :: headersInstance is NOT null
2024-05-01T15:42:33.191584Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: return result=Ok(())
2024-05-01T15:42:33.191590Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: call self_=Resource { rep: 5, state: "borrow" } contents=[104, 101, 97, 100, 101, 114, 115, 95, 104, 97, 110, 100, 108, 101, 32, 105, 115, 32, 78, 79, 84, 32, 110, 117, 108, 108, 10]
stderr [0] :: headers_handle is NOT null
2024-05-01T15:42:33.191595Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: return result=Ok(())
2024-05-01T15:42:33.191599Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: call self_=Resource { rep: 5, state: "borrow" } contents=[72, 101, 97, 100, 101, 114, 115, 58, 58, 99, 114, 101, 97, 116, 101, 32, 115, 116, 111, 114, 105, 110, 103, 32, 104, 97, 110, 100, 108, 101, 32, 48, 120, 54, 49, 55, 53, 97, 48, 32, 49, 10]
stderr [0] :: Headers::create storing handle 0x6175a0 1
2024-05-01T15:42:33.191605Z TRACE wit-bindgen export{module="wasi:http/incoming-handler@0.2.0" function="handle"}:wit-bindgen import{module="streams" function="[method]output-stream.blocking-write-and-flush"}: wasmtime_wasi::bindings::wasi::io::streams: return result=Ok(())
error: hyper::Error(User(Service), guest never invoked `response-outparam::set` method: error while executing at wasm backtrace:
    0: 0xd646fca - wit-component:shim!indirect-wasi:http/types@0.2.0-[method]fields.entries
    1: 0x4aa56 - wasi_http_0_2_0_types_method_fields_entries
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/host-apis/wasi-0.2.0/bindings/bindings.c:5665:3
    2: 0x2fdc4 - host_api::HttpHeaders::names() const
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/host-apis/wasi-0.2.0/host_api.cpp:247:3
    3: 0xde32b - builtins::web::fetch::(anonymous namespace)::get_header_names_from_handle(JSContext*, host_api::HttpHeaders*, JS::Handle<JSObject*>)
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/headers.cpp:247:24
    4: 0xde0d8 - builtins::web::fetch::Headers::create(JSContext*, JS::Handle<JSObject*>, host_api::HttpHeaders*)
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/headers.cpp:798:10
    5: 0xec5e1 - builtins::web::fetch::RequestOrResponse::headers(JSContext*, JS::Handle<JSObject*>)
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/request-response.cpp:515:15
    6: 0xebc92 - builtins::web::fetch::RequestOrResponse::extract_body(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>)
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/request-response.cpp:449:34
    7: 0xfbe9b - builtins::web::fetch::Request::create(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<JS::Value>)
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/request-response.cpp:1814:10
    8: 0xd718a - builtins::web::fetch::fetch(JSContext*, unsigned int, JS::Value*)
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/fetch-api.cpp:93:28
    9: 0x270490 - CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:472:13
   10: 0x26fcc0 - js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:566:12
   11: 0x2717b2 - InternalCall(JSContext*, js::AnyInvokeArgs const&, js::CallReason)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:633:10
   12: 0x260c13 - js::CallFromStack(JSContext*, JS::CallArgs const&, js::CallReason)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:638:10              - js::Interpret(JSContext*, js::RunState&)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:3041:16
   13: 0x257f25 - MaybeEnterInterpreterTrampoline(JSContext*, js::RunState&)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:386:10
   14: 0x257818 - js::RunScript(JSContext*, js::RunState&)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:444:13
   15: 0x26fe31 - js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:598:13
   16: 0x2717b2 - InternalCall(JSContext*, js::AnyInvokeArgs const&, js::CallReason)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:633:10
   17: 0x271b0d - js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/Interpreter.cpp:665:8
   18: 0x3adec4 - JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>)
                    at /home/runner/work/spidermonkey-wasi-embedding/spidermonkey-wasi-embedding/gecko-dev/js/src/vm/CallAndConstruct.cpp:53:10
   19: 0x10c599 - builtins::web::fetch::fetch_event::dispatch_fetch_event(JS::Handle<JSObject*>, double*)
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/fetch_event.cpp:490:10
   20: 0x10bf18 - exports_wasi_http_0_2_0_incoming_handler_handle
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/builtins/web/fetch/fetch_event.cpp:590:3
   21: 0x547a1 - __wasm_export_exports_wasi_http_0_2_0_incoming_handler_handle
                    at /Users/nicoburniske/Documents/ziverge/StarlingMonkey/host-apis/wasi-0.2.0/bindings/bindings.c:9123:3

Caused by:
    unknown handle index 1)

@nicoburniske
Copy link
Owner Author
nicoburniske commented May 1, 2024

The error guest never invoked response-outparam::set method is misleading and not the relevant one. That is a side effect of running wasmtime serve. The component is trapping and then wasmtime serve never gets a response, and then is never calling response-outparam::set.

The relevant error is unknown handle index 1

Error appears to come from accessing an invalid resource handle, which is supposed to correspond to the request http headers.

https://github.com/bytecodealliance/wasmtime/blob/66266fa9688e6fec2859d9361f36b259bde75435/crates/wasmtime/src/runtime/vm/component/resources.rs#L325

@nicoburniske nicoburniske merged commit 717c191 into main May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants