Skip to content

State clearing after FetchEvent handlingΒ #247

@vados-cosmonic

Description

@vados-cosmonic

StarlingMonkey currently cannot reuse component instances that perform HTTP request handling with the FetchEvent handler.

While production recommendation for WebAssembly components often centers around one (new) instance per request, alternatives likewasi:http handling do not suffer from this same limitation, and can handle multiple requests.

Regardless of production recommendation, StarlingMonkey should be able to handle more than one web request.

The error logs around this issue look something like the following:

Exception while dispatching FetchEvent

component.js:921:13 uncaught exception: InvalidStateError: FetchEvent#respondWith can't be called twice on the same event

The second request (that encounters the above error) hangs and never returns.

To reproduce this issue:

  1. Create a component that handles a request
  2. Set up a host embedding in which the component instance is not destroyed after serving a single request
  3. Send more than one request

More concretely, you can reproduce this behavior with one of Jco's example projects:
https://github.com/bytecodealliance/jco/tree/main/examples/components/http-server-hono

After early debugging (thanks @andreiltd !) the issue seems to be related to the clearing out of relevant state after a FetchEvent is called in the current code.

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