W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2013

Re: [whatwg] onclose events for MessagePort

From: Ian Hickson <ian@hixie.ch>
Date: Tue, 1 Oct 2013 16:58:18 +0000 (UTC)
To: Ehsan Akhgari <ehsan@mozilla.com>
Message-ID: <alpine.DEB.2.00.1310011650190.20189@ps20323.dreamhostps.com>
Cc: whatwg <whatwg@lists.whatwg.org>
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 [1] 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.   `._.-(,_..'--(,_..'`-.;.'
Received on Tuesday, 1 October 2013 16:58:43 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:11 UTC