Don't stop a Service Worker while it has in-flight requests.
Bug 445969 is the motivation for this change. Terminating
a worker while it's in the install event handler doing
waitUntil() could crash. More generally, terminating a
worker in the middle of JS execution could cause crashes
with Promises, as described in the bug.
This patch changes ServiceWorkerVersion::Doom to delay
terminating the worker until it has no inflight requests
(inflight request means it's in an event handler or has
called waitUntil). The downside is that a worker that
does while(true) or waitUntil(forever) will not be
terminated. However it is still marked REDUNDANT and
won't block the job queue.
This also doesn't completely solve the crashes. For example
the following could still crash:
oninstall = function() {
setTimeout(function() {
// Worker gets terminated here
...
}, 0);
}
Longer term, we'll also want to terminate such workers.
This can perhaps be accomplished by using a timeout and/or
altering the termination code on Blink-side so that crashes
don't occur.
An earlier solution https://codereview.chromium.org/
835103002/
was proposed but it's too specific to install event only.
BUG=445969
TEST=register-wait-forever-in-install-worker.html no longer flakes
Review URL: https://codereview.chromium.org/
804603004
Cr-Commit-Position: refs/heads/master@{#310494}