[whatwg] Worker lifecycle

Drew Wilson atwilson at google.com
Mon Apr 13 13:56:28 PDT 2009


OK, here's a more focused question - let's imagine that one is implementing
SharedWorkers in a new browser. One seemingly reasonable way to proceed
would be to have a Worker stay alive as long as there are *any* reachable
entangled ports between any window and that worker. Does this cause some
kind of problem that's addressed by the more complex behavior described in
the spec?
The "any reachable port" implementation seems like it's more along the lines
of what people would expect, and doesn't require a new concept to be tracked
(the port's original creator). I just have the nagging feeling that I'm not
properly translating from "spec language" into actual behavior, and perhaps
the intended behavior is not as complex as the spec implies.

-atw

On Fri, Apr 10, 2009 at 6:32 PM, Drew Wilson <atwilson at google.com> wrote:

> Hi all,
> A couple of quick questions about the lifecycle of workers - specifically
> I'm trying to grok the body of text at section 4.5 of the Web Workers spec.
> It seems like it's saying that if I create a shared worker, then hand off
> its port to another window, that shared worker will be orphaned once the
> original window is closed.
>
> It seems like instead of just using the normal message port reachability
> algorithm (once a worker's message ports are no longer reachable, it is
> considered orphaned) we instead have to track the original allocator of all
> ports, and only count a worker as reachable if the window that allocated the
> original port is still active.
>
> "[a worker is permissible if] at some point past or present a MessagePortowned by the worker was entangled with a
> MessagePort *p* whose owner is a Window object whose active document is
> the Document that was that browsing context's active document when *p* was
> created, and that Document is fully active"
>
> Am I reading this correctly? It just seems wonky that if I create a shared
> worker from window A, hand the port off to window B, then close window A,
> that worker is now orphaned despite being reachable from window B. But if I
> do the same thing, but before window A closes, window B creates a new port
> and sends it to the worker via the port that window A gave it, the worker
> won't be orphaned when window A closes.
>
> What's the intent here?
>
> Also, one other thing: I was previously under the impression that
> SharedWorkers had a different lifecycle from dedicated Workers -
> SharedWorkers would not exit as long as there were any windows open to that
> domain. In retrospect, I'm pretty sure I just made that up - SharedWorkers
> and dedicated Workers have identical lifecycles, correct?
>
> -atw
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090413/18257e8e/attachment-0002.htm>


More information about the whatwg mailing list