[whatwg] onclose events for MessagePort
ian at hixie.ch
Tue Oct 1 09:58:18 PDT 2013
On Tue, 1 Oct 2013, Ehsan Akhgari wrote:
> We're coming across a need to get notified when the other side of a
> channel goes away because the user navigates away from the page, or if
> the page is killed by the OS, etc.
What is that need? Can you elaborate?
> Currently a workaround is for the application to handle the unload event
> and send a message on its channel letting the other side know that it's
> going to die, but that's obviously not good enough if the application is
> terminated abruptly (e.g., crashes.)
If the browser crashes, it's not going to be able to send messages anyway,
so I'm not sure that makes sense. When would the browser be able to send a
message, but not able to properly handle unload?
> We proposed an onclose event on MessagePort to handle this case  and
> it was rejected because that would make the GC behavior observable (in
> case the port on the other side is garbage collected.) But it seems
> like tying the lifetime of MessagePorts to the lifetime of their owner
> document will fix that problem.
> Is that going to be an acceptable solution?
The problem with that is that there'd be no real way to know what the
owner Document is for an author. Suppose the port is sent to an iframe,
and then just handed over from that iframe to another iframe by just
passing it in an argument in a function, or whatnot (i.e. not transferring
it). Now the port is nowhere near the document that "owns" it.
That's why there's in fact no concept of port ownership in the spec.
Also, it would force message ports to survive being GCed up to the end of
the document's lifetime, which would essentially mean every port always
leaks until the document is closed. This is fine for many uses of ports,
but ports are also designed to be used as lightweight capability grants,
which can get vended like candy.
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg