Open
Bug 1566578
Opened 6 years ago
Updated 4 months 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)
References
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
ServiceWorkerRegistrationobject is created (as the resolve value of theregisterpromise). This object begins setting up its actors to subscribe to the correspondingServiceWorkerRegistrationInfoin the parent process for state updates. This process involves an asynchronous IPC call, so when theregisterpromise resolves, it is not guaranteed that the resultingServiceWorkerRegistrationis 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 theServiceWorkerRegistrationin the previous step can subscribe and be up-to-date with itsServiceWorkerRegistraitonInfo.
- The
readypromise resolves, with an up-to-date state, soshouldBeSameRegistration.activeis non-null, whileregistration.activeis null (registrationis 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 ServiceWorkerRegistrations 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•6 years ago
|
Priority: -- → P3
Updated•5 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•