Don't stop a Service Worker while it has in-flight requests.
commitbc4def7d325cfaba19056e960ba88335d9f88f09
authorfalken <falken@chromium.org>
Thu, 8 Jan 2015 13:49:50 +0000 (8 05:49 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 8 Jan 2015 13:50:39 +0000 (8 13:50 +0000)
tree12314f2b9678f9d7dc1176f4817167b89c5472a9
parent2efba8497683f37e27909d58701085fe2cfe8a40
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}
content/browser/service_worker/embedded_worker_instance.cc
content/browser/service_worker/service_worker_version.cc