Skip to content

Commit

Permalink
Remove overly permissive "kill a worker" algorithm
Browse files Browse the repository at this point in the history
There’s a new sheriff in town and workers can now no longer be killed.
“Kill” was a poor term to use anyway and also not needed as worker
termination already covered all angles we care about except for one.

Now, workers can solely be terminated due to close(), terminate(), or
disappearing documents.

Fixes #1004.
  • Loading branch information
annevk committed Apr 19, 2017
1 parent e1c9c2a commit 77c694e
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -97436,8 +97436,7 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {

<p class="note">In addition to the usual possibilities of returning a value or failing due to
an exception, this could be <span data-x="abort a running script">prematurely aborted</span> by
the "<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms defined
below.</p>
the <span>terminate a worker</span> algorithm defined below.</p>
</li>

<li><p>Enable <var>outside port</var>'s <span>port message queue</span>.</p></li>
Expand Down Expand Up @@ -97466,8 +97465,8 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {

<p class="note">The handling of events or the execution of callbacks by <span
data-x="concept-task">tasks</span> run by the <span>event loop</span> might get <span
data-x="abort a running script">prematurely aborted</span> by the "<span>kill a worker</span>"
or "<span>terminate a worker</span>" algorithms defined below.</p>
data-x="abort a running script">prematurely aborted</span> by the <span>terminate a
worker</span> algorithm defined below.</p>

<p class="note">The worker processing model remains on this step until the event loop is
destroyed, which happens after the <span data-x="dom-WorkerGlobalScope-closing">closing</span>
Expand Down Expand Up @@ -97499,33 +97498,6 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {

<hr>

<p>When a user agent is to <dfn data-export="">kill a worker</dfn> it must run the following steps
<span>in parallel</span> with the worker's main loop (the "<span>run a worker</span>" processing
model defined above):</p>

<ol>

<li><p>Set the worker's <code>WorkerGlobalScope</code> object's <span
data-x="dom-WorkerGlobalScope-closing">closing</span> flag to true.</p></li>

<li><p>If there are any <span data-x="concept-task">tasks</span> queued in the
<code>WorkerGlobalScope</code> object's <span>event loop</span>'s <span data-x="task queue">task
queues</span>, discard them without processing them.</p></li>

<li><p>Wait a user-agent-defined amount of time.</p></li>

<li><p><span data-x="abort a running script">Abort the script</span> currently running in the
worker.</p></li>

</ol>

<p>User agents may invoke the "<span>kill a worker</span>" processing model on a worker at any
time, e.g. in response to user requests, in response to CPU quota management, or when a worker
stops being an <span>active needed worker</span> if the worker continues executing even after its
<span data-x="dom-WorkerGlobalScope-closing">closing</span> flag was set to true.</p>

<hr>

<p>When a user agent is to <dfn data-export="">terminate a worker</dfn> it must run the following
steps <span>in parallel</span> with the worker's main loop (the "<span>run a worker</span>"
processing model defined above):</p>
Expand All @@ -97549,6 +97521,10 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {

</ol>

<p>User agents may invoke the <span>terminate a worker</span> algorithm when a worker stops being
an <span>active needed worker</span> and the worker continues executing even after its <span
data-x="dom-WorkerGlobalScope-closing">closing</span> flag was set to true.</p>

<hr>

<p>The <span>task source</span> for the tasks mentioned above is the <span>DOM manipulation task
Expand Down Expand Up @@ -97788,9 +97764,9 @@ enum <dfn>WorkerType</dfn> { "classic", "module" };

<div w-nodev>

<p>The <dfn><code data-x="dom-Worker-terminate">terminate()</code></dfn> method, when invoked, must
cause the "<span>terminate a worker</span>" algorithm to be run on the worker with which the object
is associated.</p>
<p>The <dfn><code data-x="dom-Worker-terminate">terminate()</code></dfn> method, when invoked,
must cause the <span>terminate a worker</span> algorithm to be run on the worker with which the
object is associated.</p>

<p><code>Worker</code> objects act as if they had an implicit <code>MessagePort</code> associated
with them. This port is part of a channel that is set up when the worker is created, but it is not
Expand Down Expand Up @@ -98112,8 +98088,7 @@ interface <dfn>NavigatorConcurrentHardware</dfn> {

<p class="note"><var>script</var> will run until it either returns, fails to parse, fails to
catch an exception, or gets <span data-x="abort a running script">prematurely aborted</span>
by the "<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms defined
above.</p>
by the <span>terminate a worker</span> algorithm defined above.</p>

<p>If an exception was thrown or if the script was <span data-x="abort a running
script">prematurely aborted</span>, then abort all these steps, letting the exception or
Expand Down

0 comments on commit 77c694e

Please sign in to comment.