Implement the "closing orphan workers" algorithm for dedicated workers |
||||
Issue descriptionTo terminate web workers timely, we should implement the "closing orphan workers" algorithm defined in the HTML spec: "21. Closing orphan workers: Start monitoring the worker such that no sooner than it stops being a protected worker, and no later than it stops being a permissible worker, worker global scope's closing flag is set to true." https://html.spec.whatwg.org/multipage/workers.html#worker-processing-model
,
Sep 3
,
Sep 3
Thanks for working on this!
,
Sep 4
Note, there might be something related to this currently missing from the spec. It has the "protected worker" concept to try to prevent js from observing the GC-triggered orphan worker shutdown: https://html.spec.whatwg.org/multipage/workers.html#protected-worker It seems like maybe that should include some text about BroadcastChannel, but it currently doesn't. I filed a spec issue: https://github.com/whatwg/html/issues/3993
,
Sep 4
WebLocks should also probably prevent the orphan worker cleanup: https://github.com/whatwg/html/issues/3996
,
Sep 5
wanderview@: Thank you for the information! I'll include them in the CL and design doc.
,
Sep 5
Sorry, one more thing to consider... Since the spec tries to make it so hard to observe GC its very difficult to write a WPT for this. It might be nice to try to standardize some kind of test-only interface that WPT could use to test the existance of a named worker, etc. And thanks for working on this!
,
Oct 4
I closely read the worker's spec again and noticed that the "closing orphan workers" algorithm doesn't work for the case described in c#2: > What if WorkerGlobalScope doesn't call close() and the parent context releases the Worker object without calling terminte()? In that case, the worker is considered as "orphan worker" and should be destroyed when active tasks on the worker are finished or the parent context gets destroyed. This is because in the case the owner Document still active and the worker is considered as 'active needed worker'. "A worker is said to be an active needed worker if any its owners are either Document objects that are fully active or active needed workers." https://html.spec.whatwg.org/multipage/workers.html#active-needed-worker This means the current implementation is aligned with the spec in that case. Hmm...
,
Oct 4
We might want to change the spec in order to terminate a worker in the case where there're no active tasks on WorkerGlobalScope, and 'Worker' objects in owner's contexts gets garbage collected regardless of the activeness of the owners. |
||||
►
Sign in to add a comment |
||||
Comment 1 by nhiroki@chromium.org
, Sep 3