Open Bug 1837283 Opened 11 months ago

Overhaul Worker GetCurrentSerialEventTarget() behavior to only allow same-thread dispatch unless a ThreadSafeWorkerRef is held which provides a self-perpetuating nsISerialEventTarget

Categories

(Core :: DOM: Workers, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: asuth, Unassigned)

References

Details

As proposed in my DOM meet-up presentation in April 2023 at https://docs.google.com/presentation/d/1Y-f1veyNjSfsvqaT42ATft8RQmfuh3Qm3gxrPLVTrHE/edit?usp=sharing the tentative plan to avoid lifecycle problems arising from code on workers is to provide consistency so that it's necessary to be holding a ThreadSafeWorkerRef and explicitly using an RAII guard it provides or retrieving its exposed nsISerialEventTarget whenever an nsISerialEventTarget is desired that can be used for dispatch purposes from off the worker thread. Runnables that run on the ThreadSafeWorkerRef-provided event target will automatically have the guard applied so that their code will see that same target when they call GetCurrentSerialEventTarget().

Code that uses IPC will not need to do anything special because the IPC IO/worker thread will explicitly be allowed to dispatch to the worker thread because IPC lifecycle management is already able to conform to worker lifecycles through use of nsIEventTarget shutdown tasks or through workers' own explicit control of PBackground. This also inherently applies to any MozPromises chained off async IPC binding calls that use GetCurrentSerialEventTarget(). (But a MozPromise that explicitly is bouncing to another thread and then back to the worker thread will need to use the new ThreadSafeWorkerRef event target mechanism.)

You need to log in before you can comment on or make changes to this bug.