whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.08k stars 2.66k forks source link

Worklet termination #10169

Open daxpedda opened 7 months ago

daxpedda commented 7 months ago

What problem are you trying to solve?

A way to clean up multi-threaded Wasm resources when a worklet is garbage collected or otherwise finished/closed.

One way to currently do this with dedicated workers:

Unfortunately this can't be done in worklets because they can't block, therefor there is no way to ensure that Wasm resources aren't being accessed.

What solutions exist today?

The best alternative is to invalidate the Wasm module and making any call to it throw, which doesn't solve the problem but at least prevents unsoundness.

How would you solve it?

A way to terminate worklets, like Worker.terminate() and an event that is triggered when the worklet closes. Alternatively only an event if worklets can be properly garbage collected even with a Wasm module.

I'm unsure how FinalizationRegistry could be used here instead of the event.

Anything else?

This is coming from https://github.com/WebAudio/web-audio-api/issues/2568.

annevk commented 7 months ago

Somewhat related: #10136.

annevk commented 7 months ago

cc @padenot @hoch