Bug 191986 - Updating a service worker during a navigation load sometimes makes the load fail
Summary: Updating a service worker during a navigation load sometimes makes the load fail
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-11-26 15:47 PST by youenn fablet
Modified: 2018-11-29 12:11 PST (History)
6 users (show)

See Also:


Attachments
Patch (13.16 KB, patch)
2018-11-28 10:38 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews123 for ios-simulator-wk2 (17.00 MB, application/zip)
2018-11-28 12:50 PST, EWS Watchlist
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2018-11-26 15:47:32 PST
According https://github.com/PWA-POLICE/pwa-bugs#problem-navigation-to-a-website-has-infinite-loading, updating a service worker during a navigation load sometimes trigger terminating a service worker that serves the content for a page, hence making the load fail.
Comment 1 Radar WebKit Bug Importer 2018-11-26 15:49:11 PST
<rdar://problem/46259790>
Comment 2 Chris Dumez 2018-11-27 11:41:42 PST
Seems to indicate that our TryActivate implementation is actually activating the newly installed worker even though there is already an active worker with clients.

https://w3c.github.io/ServiceWorker/#try-activate
Comment 3 Chris Dumez 2018-11-27 11:43:13 PST
Our tryActivate implementation does:
    // Invoke Activate with registration if either of the following is true:
    // - registration's active worker is null.
    // - The result of running Service Worker Has No Pending Events with registration's active worker is true,
    //   and no service worker client is using registration or registration's waiting worker's skip waiting flag is set.
    if (!activeWorker() || (!activeWorker()->hasPendingEvents() && (!hasClientsUsingRegistration() || waitingWorker()->isSkipWaitingFlagSet())))
        activate();

So somehow, even though there is an active worker and a pending load handled by that worker, we still call activate().
Comment 4 youenn fablet 2018-11-27 13:22:32 PST
We are probably registering the new document too late as a service worker client.
Currently we are creating/registering the Document when receiving the first data bytes which is too late.
Ideally, we should probably register the document as soon as we send the fetch event to the service worker.

Another approach would be to keep track of navigation loads a service worker is responsible for and update the activate logic according that new information.
Comment 5 youenn fablet 2018-11-28 10:38:19 PST
Created attachment 355889 [details]
Patch
Comment 6 youenn fablet 2018-11-28 10:38:52 PST
Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/14286
Comment 7 EWS Watchlist 2018-11-28 12:50:00 PST
Comment on attachment 355889 [details]
Patch

Attachment 355889 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10185320

New failing tests:
imported/w3c/web-platform-tests/webrtc/simplecall-no-ssrcs.https.html
media/no-fullscreen-when-hidden.html
Comment 8 EWS Watchlist 2018-11-28 12:50:03 PST
Created attachment 355907 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 9 youenn fablet 2018-11-28 14:09:16 PST
Comment on attachment 355907 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

Error is unrelated
Comment 10 WebKit Commit Bot 2018-11-29 12:11:01 PST
Comment on attachment 355889 [details]
Patch

Clearing flags on attachment: 355889

Committed r238683: <https://trac.webkit.org/changeset/238683>
Comment 11 WebKit Commit Bot 2018-11-29 12:11:03 PST
All reviewed patches have been landed.  Closing bug.