Open
Bug 1566578
Opened 5 years ago
Updated 4 years ago
Resolution of a ready promise acquired before registering a new Service Worker may race
Categories
(Core :: DOM: Service Workers, defect, P3)
Core
DOM: Service Workers
Tracking
()
NEW
People
(Reporter: perry, Unassigned)
Details
This issue only applies to parent-intercept mode. Assume there are no existing Service Worker registrations. Consider:
const readyPromise = navigator.serviceWorker.ready;
const registration = await navigator.serviceWorker.register('./sw.js');
const shouldBeSameRegistration = await readyPromise;
assert(registration.active.scriptURL === shouldBeSameRegistration.active.scriptURL);
registration.active
could be null
(when it should be non-null
) if this is what's going on:
- The install algorithm runs in the parent process, initiating the resolution of the promise returned by
navigator.serviceWorker.register
. - In parallel,
- In the content process, a
ServiceWorkerRegistration
object is created (as the resolve value of theregister
promise). This object begins setting up its actors to subscribe to the correspondingServiceWorkerRegistrationInfo
in the parent process for state updates. This process involves an asynchronous IPC call, so when theregister
promise resolves, it is not guaranteed that the resultingServiceWorkerRegistration
is in sync with the parent process data. - In the parent process, the worker transitions to the activate state, initiating the resolution of the promise returned by
navigator.serviceWorker.ready
. The calls to do this propagate to the content process before theServiceWorkerRegistration
in the previous step can subscribe and be up-to-date with itsServiceWorkerRegistraitonInfo
.
- The
ready
promise resolves, with an up-to-date state, soshouldBeSameRegistration.active
is non-null, whileregistration.active
is null (registration
is not up-to-date).
To solve this, before resolving the ready promise corresponding to a given ServiceWorkerRegistrationInfo
, we need to be aware of all associated ServiceWorkerRegistration
s and ensure that they're up-to-date. Specifically, the spec's "Update Registration State" algorithm states
Let registrationObjects be an array containing all the ServiceWorkerRegistration objects associated with registration.
and it seems that we don't always have all these objects when we need them.
Reporter | ||
Updated•5 years ago
|
Priority: -- → P3
Updated•4 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•