Skip to content

Regression in fetch-event example using jco 1.10.2 and componentize-js 0.18.0 #625

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

Open
rajsite opened this issue Apr 2, 2025 · 4 comments
Labels
bug Something isn't working examples regression Regression/re-introduction of a bug upstream/componentize-js

Comments

@rajsite
Copy link
Contributor

rajsite commented Apr 2, 2025

I had the following example working correctly with jco 1.9.1, componentize-js 0.16.0, wasmtime 31.0.0 in a WSL 2 ubuntu linux environment:

{
  const { addEventListener } = globalThis;

  addEventListener(
    "fetch", (event) =>
    event.respondWith(
      (async () => {
        try {
          console.log('start httpbin request');
          const request = await fetch('https://httpbin.org/json');
          const result = await request.text();
          console.log('finish httpbin request');
          return new Response(`Hello from TypeScript!, result: ${result}`);
        } catch (e) {
          console.error(e);
          return new Response('whoopsies');
        }
      })(),
    ),
  );
}

I could build the example, run with wasmtime serve --addr 0.0.0.0:8000 -S cli=y dist/main.wasm and see output like the following when visited in the browser:

Hello from TypeScript!, result: {
  "slideshow": {
    "author": "Yours Truly", 
    "date": "date of publication", 
    "slides": [
      {
        "title": "Wake up to WonderWidgets!", 
        "type": "all"
      }, 
      {
        "items": [
          "Why <em>WonderWidgets</em> are great", 
          "Who <em>buys</em> WonderWidgets"
        ], 
        "title": "Overview", 
        "type": "all"
      }
    ], 
    "title": "Sample Slide Show"
  }
}

When I upgrade to jco 1.10.2, componentize-js 0.18.0, and keep the same wasmtime 31.0.0 in a WSL 2 ubuntu linux environment I get the following console error when visiting the endpoint with wasmtime serve:

> wasmtime serve --addr 0.0.0.0:8000 -S cli=y dist/main.wasm

Serving HTTP on http://0.0.0.0:8000/
2025-04-02T02:30:26.260665Z ERROR wasmtime_cli::commands::serve: [0] :: error while executing at wasm backtrace:
    0: 0x80fb90 - <unknown>!environ_sizes_get
    1: 0x775799 - <unknown>!<wasm function 12652>
    2: 0x7a05be - <unknown>!<wasm function 12889>

Caused by:
    wasm trap: wasm `unreachable` instruction executed    
error: hyper::Error(User(Service), guest never invoked `response-outparam::set` method

Caused by:
    0: error while executing at wasm backtrace:
           0: 0x80fb90 - <unknown>!environ_sizes_get
           1: 0x775799 - <unknown>!<wasm function 12652>
           2: 0x7a05be - <unknown>!<wasm function 12889>
    1: wasm trap: wasm `unreachable` instruction executed)

I created a successful reproduction and a failing reproduction. In both examples:

  • npm install
  • npm run build
  • npm run start-wasmtime
  • Visit localhost:8000 in the browser

js-app.zip
js-app-fails.zip

@rajsite
Copy link
Contributor Author

rajsite commented Apr 7, 2025

The stack trace in the repro linked from the following issue looks very similar, might be the same issue? bytecodealliance/ComponentizeJS#194 (comment)

@karthik2804
Copy link

It appears to be the same issue. The workaround right now is to include the wasi:cli/[email protected] as an import on the target wit world.

@rajsite
Copy link
Contributor Author

rajsite commented Apr 10, 2025

Thanks @karthik2804! Updating the wit in the above examples to:

package main-namespace:main-package;

world main-world {
  import wasi:cli/[email protected];
  export wasi:http/[email protected];
}

unblocked me from upgrading to @bytecodealliance/[email protected] and @bytecodealliance/[email protected] 🎉

@vados-cosmonic
Copy link
Collaborator

Hey @rajsite incredibly late here, but yes -- this is partially why we haven't upgraded to 0.18.0 at present (our examples also break in CI), there were also some other problems (for which a fix has now been merged) -- we're waiting on a release of componentize-js as well :)

Once we're able to get jco updated to componentize-js to 0.18.3 (or whatever the new version ends up being), I'll close this out.

@vados-cosmonic vados-cosmonic added bug Something isn't working upstream/componentize-js examples regression Regression/re-introduction of a bug labels May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working examples regression Regression/re-introduction of a bug upstream/componentize-js
Projects
None yet
Development

No branches or pull requests

3 participants