-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
navigator.serviceWorker.ready depends subtly on timing of registration, some calls get "stuck" #357
Comments
A document may have its Service Worker registration, represented by a [[Registration]] object in the spec, during its lifetime. Once the document obtains a [[Registration]] object, the only chance it goes defunct is the unregister() call. And as such, multiple registration attempts nothing but update the active worker within the same [[Registration]] object. I thought of the behavior of the
Am I misunderstanding your concern here? |
If you look at ready step 2.3 it does [[MatchScope]] to read the [[ScopeToRegistrationMap]] and produce a registration object. Other calls to register with different scopes, but whose scopes also match the document, may write into the [[ScopeToRegistrationMap]]. So the ready property may watch different registrations depending on when it is invoked (because step 2.3/[[MatchScope]] may return a different, new registration.) Because only one Service Worker can be "active" for a document, some of these registrations will "lose" and one of them will "win". Scripts that accessed navigator.serviceWorker.ready and unluckily started watching a "loser" will never get resolved (neither will they get rejected, because ready does not reject either.) I think you want to consider how Issue 365 affects ready, too. |
Yeah, I'll revisit |
Implementer feedback: Blink has updated its implementation of ready; it used to resolve with the "current" ServiceWorker; now it resolves with the active worker. Further, it ignores specific registrations and resolves when the matching registration (in terms of [[MatchScope]]) has an active worker. In this way none of them get "stuck" observing a registration. This also makes reusing a Promise over multiple property accesses feasible in more cases. |
@coonsta What do you mean by "ignores specific registrations"? |
@coonsta friendly ping for nikhilm's question. |
So
Using the [[MatchScope]] algorithm means that even if the page is controlled, the registration returned by ready may not be the one controlling the page. But what is the page waiting for then? Sorry if I'm misunderstanding, but the use cases for ready confuse me. Maybe a non-normative section in the spec to document this would be nice too. For now Gecko is going to only have one Promise ever, and once that resolves, that's it. It will be trivial to follow Blink's path if this issue is resolved so. |
I suppose @coonsta just meant the same thing as:
I think
That is,
It seems this behavior would cover the following use case better: navigator.serviceWorker.ready.then(function(swr) {
swr.pushRegistrationManager.doStuff();
}); If |
@jungkees Would it be possible to reflect your previous comment and so on to the ready algorithm? Especially, I'm interested in the timing to resolve the ready promise ([[Activate]] 1.7. ?). I'm going to update the .ready implementation in Blink if necessary (http://crbug.com/399533). |
Just updated the algorithm: ffaa0fb. The idea behind the algorithm has not been changed. Please let me know if it's different from what has been expected. |
@nhiroki could you confirm that the change doesn't impact Blink (I believe so) |
@jungkees Thank you for updating! Yes, that's what I expected. @KenjiBaheux Confirmed. This was fixed in Blink (http://crbug.com/399533). |
This small powerful change passes the service worker registration directly to the WikiWorker. To avoid massive indents and make my code easier to read I add a getRegisteredWorker function - but there's no need for it to be async :) A new WikiWorker gets attached to the button and this clears the way for me not having to work in global scope. See w3c/ServiceWorker#357 to avoid confusion.
The "ready" algorithm step 2.3 finds a registration, then waits for it to have an activeWorker (step 4.) This means that if there is interleaved registrations and access to navigator.serviceWorker.ready, some of those ready Promises can get "stuck" observing defunct registrations.
This seems contrary to the use cases I understand for "ready" which are to get a Service Worker that is ready to handle messages/requests/etc., because in some cases those .ready invocations go into a black hole.
The text was updated successfully, but these errors were encountered: