Closed Bug 1472005 Opened 6 years ago Closed 6 years ago

wait for registration state to update before resolving ready promise

Categories

(Core :: DOM: Service Workers, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla63
Tracking Status
firefox63 --- fixed

People

(Reporter: bkelly, Assigned: mrbkap)

References

Details

Attachments

(1 file, 1 obsolete file)

In IPC mode sometimes the navigator.serviceWorker.ready promise would resolve with a slightly out-of-date registration.  In particular, the registration.active property would be null.  This should be impossible according to the spec.
Blocks: 1472008
Comment on attachment 8988605 [details] [diff] [review]
Don't resolve ready promise until the registration has reached the right state version. r=mrbkap

Similar to how registration state triggering an updatefound event raced with the update() promise, we also have an issue with registration state changes racing with the navigator.serviceWorker.ready promise.

The ready promise is resolved in step 7.2 here:

https://w3c.github.io/ServiceWorker/#activation-algorithm

This happens after the registration and worker state have been updated.

This can break in IPC mode when the container and registration need to connect to the parent upon creation.  We want to replay the version change list to make sure events are fired correctly, but a site may also immediately access the ready promise.  If the ready promise resolves immediately before the change list has been replayed, then the script may see a resolved ready promise reaction before the registration.active property is set.

This patch fixes the problem by making the .ready code delay resolving the promise until the binding object has reached the correct state version.
Attachment #8988605 - Flags: review?(mrbkap)
Priority: -- → P2
Comment on attachment 8988605 [details] [diff] [review]
Don't resolve ready promise until the registration has reached the right state version. r=mrbkap

Review of attachment 8988605 [details] [diff] [review]:
-----------------------------------------------------------------

This is really cool. It's exactly the patch I expected to see.
Attachment #8988605 - Flags: review?(mrbkap) → review+
Try build in comment 1.
Keywords: checkin-needed
Patch failed to apply:

mozilla@ubuntu:~/mozilla-unified$ hg qpush
applying bug1472005_ready.patch
patching file dom/serviceworkers/ServiceWorkerRegistration.cpp
Hunk #1 FAILED at 152
Hunk #2 FAILED at 336
2 out of 2 hunks FAILED -- saving rejects to file dom/serviceworkers/ServiceWorkerRegistration.cpp.rej
patching file dom/serviceworkers/ServiceWorkerRegistration.h
Hunk #1 succeeded at 115 with fuzz 1 (offset 0 lines).
Hunk #2 FAILED at 145
1 out of 2 hunks FAILED -- saving rejects to file dom/serviceworkers/ServiceWorkerRegistration.h.rej
patch failed, unable to continue (try -v)
patch failed, rejects left in working directory
errors during apply, please fix and qrefresh bug1472005_ready.patch
Flags: needinfo?(ben)
Flags: needinfo?(ben)
Assignee: ben → mrbkap
Pushed by ben@wanderview.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/4eb950e44164
Don't resolve ready promise until the registration has reached the right state version. r=mrbkap
https://hg.mozilla.org/mozilla-central/rev/4eb950e44164
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: