-
Notifications
You must be signed in to change notification settings - Fork 45
Description
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:
- Create a component that handles a request
- Set up a host embedding in which the component instance is not destroyed after serving a single request
- 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.