Skip to content

Commit

Permalink
[giow] (0) Add a way to catch the other side of a port having a catas…
Browse files Browse the repository at this point in the history
…trophic death.

Affected topics: DOM APIs

git-svn-id: http://svn.whatwg.org/webapps@8336 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Dec 7, 2013
1 parent d7ae24d commit 22ef1e0
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 15 deletions.
41 changes: 36 additions & 5 deletions complete.html
Expand Up @@ -298,7 +298,7 @@

<header class=head id=head><p><a href=http://www.whatwg.org/ class=logo><img width=101 src=/images/logo alt=WHATWG height=101></a></p>
<hgroup><h1 class=allcaps>HTML</h1>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 6 December 2013</h2>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 7 December 2013</h2>
</hgroup><dl><dt><strong>Web developer edition:</strong></dt>
<dd><strong><a href=http://developers.whatwg.org/>http://developers.whatwg.org/</a></strong></dd>
<dt>Multiple-page version:</dt>
Expand Down Expand Up @@ -80377,6 +80377,7 @@ <h4 id=message-ports><span class=secno>9.5.3 </span>Message ports</h4>

// event handlers
attribute <a href=#eventhandler>EventHandler</a> <a href=#handler-messageport-onmessage title=handler-MessagePort-onmessage>onmessage</a>;
attribute <a href=#eventhandler>EventHandler</a> <a href=#handler-messageport-onerror title=handler-MessagePort-onerror>onerror</a>;
};
// <a href=#messageport>MessagePort</a> implements <a href=#transferable>Transferable</a>;</pre>

Expand Down Expand Up @@ -80739,13 +80740,41 @@ <h4 id=message-ports><span class=secno>9.5.3 </span>Message ports</h4>
disentangle the two ports. If the method is called on a port that is not entangled, then the
method must do nothing.</p>

<hr><p>In some circumstances, an entangled <code><a href=#messageport>MessagePort</a></code> <var title="">source port</var>
that is not <a href=#ports-and-garbage-collection>eligible for garbage collection</a> will
nonetheless find itself prematurely destroyed, for example if the user manually terminates the
user agent's host process. Under such circumstances, user agents should attempt to following these
steps:</p>

<!-- don't fire this for navigation, it would break bfcache -->
<!-- for consistency, we don't fire this for worker termination -->
<!-- we don't fire it on .close() because that would let you probe GC behaviour also -->

<ol><li><p>Let <var title="">target port</var> be the port with which the ill-fated <var title="">source port</var> is entangled.</li>

<li><p>If there is no <var title="">target port</var> (i.e. if <var title="">source port</var>
is not entangled), or if <var title="">target port</var> is suffering the same fate as <var title="">source port</var> (e.g. if both ports are in the same host process), then abort these
steps.</li>

<li><p><a href=#queue-a-task>Queue a task</a> to <a href=#fire-a-simple-event>fire a simple event</a> named <code title=event-error>error</code> at <var title="">target port</var>. The <a href=#concept-task title=concept-task>task</a> must be associated with the <a href=#responsible-document>responsible document</a>
specified by <var title="">source port</var>'s <a href=#concept-port-owner title=concept-port-owner>owner</a>,
and must use the <a href=#dom-manipulation-task-source>DOM manipulation task source</a>.</li>

<li><p>Disentangle the two ports.</li>

</ol><p class=note>This does not happen if the port is garbage collected or closed using the <code title=dom-messageport-close><a href=#dom-messageport-close>close()</a></code> method. It is intended only as a way for Web
applications that operate across multiple browser processes (e.g. using workers or communicating
across multiple tabs) to gracefully handle a catastrophic failure in one process. A strictly
conforming user agent would never fail unexpectedly, and thus would never send this event!</p>

<hr><p>The following are the <a href=#event-handlers>event handlers</a> (and their corresponding <a href=#event-handler-event-type title="event
handler event type">event handler event types</a>) that must be supported, as <a href=#event-handler-idl-attributes>event
handler IDL attributes</a>, by all objects implementing the <code><a href=#messageport>MessagePort</a></code>
interface:</p>

<table><thead><tr><th><a href=#event-handlers title="event handlers">Event handler</a> <th><a href=#event-handler-event-type>Event handler event type</a>
<tbody><tr><td><dfn id=handler-messageport-onmessage title=handler-MessagePort-onmessage><code>onmessage</code></dfn> <td> <code title=event-message><a href=#event-message>message</a></code>
<tr><td><dfn id=handler-messageport-onerror title=handler-MessagePort-onerror><code>onerror</code></dfn> <td> <code title=event-error>error</code>
</table><p>The first time a <code><a href=#messageport>MessagePort</a></code> object's <code title=handler-MessagePort-onmessage><a href=#handler-messageport-onmessage>onmessage</a></code> IDL attribute is set, the port's <a href=#port-message-queue>port
message queue</a> must be enabled, as if the <code title=dom-MessagePort-start><a href=#dom-messageport-start>start()</a></code>
method had been called.</p>
Expand Down Expand Up @@ -80877,12 +80906,13 @@ <h4 id=ports-and-garbage-collection><span class=secno>9.5.5 </span>Ports and gar

</div>

<!--CLEANUP-->
<p>Furthermore, a <code><a href=#messageport>MessagePort</a></code> object must not be garbage collected while there exists
a message in a <a href=#task-queue>task queue</a> that is to be dispatched on that <code><a href=#messageport>MessagePort</a></code>
object, or while the <code><a href=#messageport>MessagePort</a></code> object's <a href=#port-message-queue>port message queue</a> is open and
an event in a <a href=#task-queue>task queue</a> that is to be dispatched on that <code><a href=#messageport>MessagePort</a></code>
object, or while the <code><a href=#messageport>MessagePort</a></code> object's <a href=#port-message-queue>port message queue</a> is enabled and
there exists a <code title=event-message><a href=#event-message>message</a></code> event in that queue.</p> <!-- we might
not need to explicitly say the first part if DOM Events is fixed to say that events on a task
queue prevent GC -->
queue prevent GC, and the second part really is pretty redundant so maybe we don't need that either -->

<!-- ports in the ports attribute of a MessageEvent that isn't dispatched yet are safe because the
MessageEvent is safe -->
Expand All @@ -80897,7 +80927,8 @@ <h4 id=ports-and-garbage-collection><span class=secno>9.5.5 </span>Ports and gar
<p class=note>Authors are strongly encouraged to explicitly close <code><a href=#messageport>MessagePort</a></code>
objects to disentangle them, so that their resources can be recollected. Creating many
<code><a href=#messageport>MessagePort</a></code> objects and discarding them without closing them can lead to high
transient memory usage since garbage collection is not necessarily performed promptly.</p>
transient memory usage since garbage collection is not necessarily performed promptly, especially
for <code><a href=#messageport>MessagePort</a></code>s where garbage collection can involve cross-process coordination.</p>

<!--POSTMSG-->

Expand Down
41 changes: 36 additions & 5 deletions index
Expand Up @@ -298,7 +298,7 @@

<header class=head id=head><p><a href=http://www.whatwg.org/ class=logo><img width=101 src=/images/logo alt=WHATWG height=101></a></p>
<hgroup><h1 class=allcaps>HTML</h1>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 6 December 2013</h2>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 7 December 2013</h2>
</hgroup><dl><dt><strong>Web developer edition:</strong></dt>
<dd><strong><a href=http://developers.whatwg.org/>http://developers.whatwg.org/</a></strong></dd>
<dt>Multiple-page version:</dt>
Expand Down Expand Up @@ -80377,6 +80377,7 @@ interface <dfn id=messagechannel>MessageChannel</dfn> {

// event handlers
attribute <a href=#eventhandler>EventHandler</a> <a href=#handler-messageport-onmessage title=handler-MessagePort-onmessage>onmessage</a>;
attribute <a href=#eventhandler>EventHandler</a> <a href=#handler-messageport-onerror title=handler-MessagePort-onerror>onerror</a>;
};
// <a href=#messageport>MessagePort</a> implements <a href=#transferable>Transferable</a>;</pre>

Expand Down Expand Up @@ -80739,13 +80740,41 @@ interface <dfn id=messagechannel>MessageChannel</dfn> {
disentangle the two ports. If the method is called on a port that is not entangled, then the
method must do nothing.</p>

<hr><p>In some circumstances, an entangled <code><a href=#messageport>MessagePort</a></code> <var title="">source port</var>
that is not <a href=#ports-and-garbage-collection>eligible for garbage collection</a> will
nonetheless find itself prematurely destroyed, for example if the user manually terminates the
user agent's host process. Under such circumstances, user agents should attempt to following these
steps:</p>

<!-- don't fire this for navigation, it would break bfcache -->
<!-- for consistency, we don't fire this for worker termination -->
<!-- we don't fire it on .close() because that would let you probe GC behaviour also -->

<ol><li><p>Let <var title="">target port</var> be the port with which the ill-fated <var title="">source port</var> is entangled.</li>

<li><p>If there is no <var title="">target port</var> (i.e. if <var title="">source port</var>
is not entangled), or if <var title="">target port</var> is suffering the same fate as <var title="">source port</var> (e.g. if both ports are in the same host process), then abort these
steps.</li>

<li><p><a href=#queue-a-task>Queue a task</a> to <a href=#fire-a-simple-event>fire a simple event</a> named <code title=event-error>error</code> at <var title="">target port</var>. The <a href=#concept-task title=concept-task>task</a> must be associated with the <a href=#responsible-document>responsible document</a>
specified by <var title="">source port</var>'s <a href=#concept-port-owner title=concept-port-owner>owner</a>,
and must use the <a href=#dom-manipulation-task-source>DOM manipulation task source</a>.</li>

<li><p>Disentangle the two ports.</li>

</ol><p class=note>This does not happen if the port is garbage collected or closed using the <code title=dom-messageport-close><a href=#dom-messageport-close>close()</a></code> method. It is intended only as a way for Web
applications that operate across multiple browser processes (e.g. using workers or communicating
across multiple tabs) to gracefully handle a catastrophic failure in one process. A strictly
conforming user agent would never fail unexpectedly, and thus would never send this event!</p>

<hr><p>The following are the <a href=#event-handlers>event handlers</a> (and their corresponding <a href=#event-handler-event-type title="event
handler event type">event handler event types</a>) that must be supported, as <a href=#event-handler-idl-attributes>event
handler IDL attributes</a>, by all objects implementing the <code><a href=#messageport>MessagePort</a></code>
interface:</p>

<table><thead><tr><th><a href=#event-handlers title="event handlers">Event handler</a> <th><a href=#event-handler-event-type>Event handler event type</a>
<tbody><tr><td><dfn id=handler-messageport-onmessage title=handler-MessagePort-onmessage><code>onmessage</code></dfn> <td> <code title=event-message><a href=#event-message>message</a></code>
<tr><td><dfn id=handler-messageport-onerror title=handler-MessagePort-onerror><code>onerror</code></dfn> <td> <code title=event-error>error</code>
</table><p>The first time a <code><a href=#messageport>MessagePort</a></code> object's <code title=handler-MessagePort-onmessage><a href=#handler-messageport-onmessage>onmessage</a></code> IDL attribute is set, the port's <a href=#port-message-queue>port
message queue</a> must be enabled, as if the <code title=dom-MessagePort-start><a href=#dom-messageport-start>start()</a></code>
method had been called.</p>
Expand Down Expand Up @@ -80877,12 +80906,13 @@ callback <dfn id=portcollectioncallback>PortCollectionCallback</dfn> = void (<a

</div>

<!--CLEANUP-->
<p>Furthermore, a <code><a href=#messageport>MessagePort</a></code> object must not be garbage collected while there exists
a message in a <a href=#task-queue>task queue</a> that is to be dispatched on that <code><a href=#messageport>MessagePort</a></code>
object, or while the <code><a href=#messageport>MessagePort</a></code> object's <a href=#port-message-queue>port message queue</a> is open and
an event in a <a href=#task-queue>task queue</a> that is to be dispatched on that <code><a href=#messageport>MessagePort</a></code>
object, or while the <code><a href=#messageport>MessagePort</a></code> object's <a href=#port-message-queue>port message queue</a> is enabled and
there exists a <code title=event-message><a href=#event-message>message</a></code> event in that queue.</p> <!-- we might
not need to explicitly say the first part if DOM Events is fixed to say that events on a task
queue prevent GC -->
queue prevent GC, and the second part really is pretty redundant so maybe we don't need that either -->

<!-- ports in the ports attribute of a MessageEvent that isn't dispatched yet are safe because the
MessageEvent is safe -->
Expand All @@ -80897,7 +80927,8 @@ callback <dfn id=portcollectioncallback>PortCollectionCallback</dfn> = void (<a
<p class=note>Authors are strongly encouraged to explicitly close <code><a href=#messageport>MessagePort</a></code>
objects to disentangle them, so that their resources can be recollected. Creating many
<code><a href=#messageport>MessagePort</a></code> objects and discarding them without closing them can lead to high
transient memory usage since garbage collection is not necessarily performed promptly.</p>
transient memory usage since garbage collection is not necessarily performed promptly, especially
for <code><a href=#messageport>MessagePort</a></code>s where garbage collection can involve cross-process coordination.</p>

<!--POSTMSG-->

Expand Down
52 changes: 47 additions & 5 deletions source
Expand Up @@ -90077,6 +90077,7 @@ interface <dfn>MessageChannel</dfn> {

// event handlers
attribute <span>EventHandler</span> <span data-x="handler-MessagePort-onmessage">onmessage</span>;
attribute <span>EventHandler</span> <span data-x="handler-MessagePort-onerror">onerror</span>;
};
// <span>MessagePort</span> implements <span>Transferable</span>;</pre>

Expand Down Expand Up @@ -90490,6 +90491,44 @@ interface <dfn>MessageChannel</dfn> {

<hr>

<p>In some circumstances, an entangled <code>MessagePort</code> <var data-x="">source port</var>
that is not <a href="#ports-and-garbage-collection">eligible for garbage collection</a> will
nonetheless find itself prematurely destroyed, for example if the user manually terminates the
user agent's host process. Under such circumstances, user agents should attempt to following these
steps:</p>

<!-- don't fire this for navigation, it would break bfcache -->
<!-- for consistency, we don't fire this for worker termination -->
<!-- we don't fire it on .close() because that would let you probe GC behaviour also -->

<ol>

<li><p>Let <var data-x="">target port</var> be the port with which the ill-fated <var
data-x="">source port</var> is entangled.</p></li>

<li><p>If there is no <var data-x="">target port</var> (i.e. if <var data-x="">source port</var>
is not entangled), or if <var data-x="">target port</var> is suffering the same fate as <var
data-x="">source port</var> (e.g. if both ports are in the same host process), then abort these
steps.</p></li>

<li><p><span>Queue a task</span> to <span>fire a simple event</span> named <code
data-x="event-error">error</code> at <var data-x="">target port</var>. The <span
data-x="concept-task">task</span> must be associated with the <span>responsible document</span>
specified by <var data-x="">source port</var>'s <span data-x="concept-port-owner">owner</span>,
and must use the <span>DOM manipulation task source</span>.</p></li>

<li><p>Disentangle the two ports.</p></li>

</ol>

<p class="note">This does not happen if the port is garbage collected or closed using the <code
data-x="dom-messageport-close">close()</code> method. It is intended only as a way for Web
applications that operate across multiple browser processes (e.g. using workers or communicating
across multiple tabs) to gracefully handle a catastrophic failure in one process. A strictly
conforming user agent would never fail unexpectedly, and thus would never send this event!</p>

<hr>

<p>The following are the <span>event handlers</span> (and their corresponding <span data-x="event
handler event type">event handler event types</span>) that must be supported, as <span>event
handler IDL attributes</span>, by all objects implementing the <code>MessagePort</code>
Expand All @@ -90500,6 +90539,7 @@ interface <dfn>MessageChannel</dfn> {
<tr><th><span data-x="event handlers">Event handler</span> <th><span>Event handler event type</span>
<tbody>
<tr><td><dfn data-x="handler-MessagePort-onmessage"><code>onmessage</code></dfn> <td> <code data-x="event-message">message</code>
<tr><td><dfn data-x="handler-MessagePort-onerror"><code>onerror</code></dfn> <td> <code data-x="event-error">error</code>
</table>

<p>The first time a <code>MessagePort</code> object's <code
Expand Down Expand Up @@ -90622,7 +90662,7 @@ callback <dfn>PortCollectionCallback</dfn> = void (<span>MessagePort</span> port
</div>


<h4>Ports and garbage collection</h4>
<h4 id="ports-and-garbage-collection">Ports and garbage collection</h4>

<div class="impl">

Expand All @@ -90643,12 +90683,13 @@ callback <dfn>PortCollectionCallback</dfn> = void (<span>MessagePort</span> port

</div>

<!--CLEANUP-->
<p>Furthermore, a <code>MessagePort</code> object must not be garbage collected while there exists
a message in a <span>task queue</span> that is to be dispatched on that <code>MessagePort</code>
object, or while the <code>MessagePort</code> object's <span>port message queue</span> is open and
an event in a <span>task queue</span> that is to be dispatched on that <code>MessagePort</code>
object, or while the <code>MessagePort</code> object's <span>port message queue</span> is enabled and
there exists a <code data-x="event-message">message</code> event in that queue.</p> <!-- we might
not need to explicitly say the first part if DOM Events is fixed to say that events on a task
queue prevent GC -->
queue prevent GC, and the second part really is pretty redundant so maybe we don't need that either -->

<!-- ports in the ports attribute of a MessageEvent that isn't dispatched yet are safe because the
MessageEvent is safe -->
Expand All @@ -90663,7 +90704,8 @@ callback <dfn>PortCollectionCallback</dfn> = void (<span>MessagePort</span> port
<p class="note">Authors are strongly encouraged to explicitly close <code>MessagePort</code>
objects to disentangle them, so that their resources can be recollected. Creating many
<code>MessagePort</code> objects and discarding them without closing them can lead to high
transient memory usage since garbage collection is not necessarily performed promptly.</p>
transient memory usage since garbage collection is not necessarily performed promptly, especially
for <code>MessagePort</code>s where garbage collection can involve cross-process coordination.</p>

<!--END postmsg--><!--POSTMSG-->

Expand Down

0 comments on commit 22ef1e0

Please sign in to comment.