Bug 180573 - Delay some service worker operations until after the database import completes
Summary: Delay some service worker operations until after the database import completes
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: Brady Eidson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-07 22:59 PST by Brady Eidson
Modified: 2018-01-02 13:00 PST (History)
7 users (show)

See Also:


Attachments
Patch (14.69 KB, patch)
2017-12-07 23:15 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (3.51 MB, application/zip)
2017-12-08 00:41 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews124 for ios-simulator-wk2 (60.87 MB, application/zip)
2017-12-08 01:36 PST, EWS Watchlist
no flags Details
Patch (15.46 KB, patch)
2017-12-08 12:22 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch (15.55 KB, patch)
2017-12-08 14:05 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch (15.61 KB, patch)
2017-12-08 14:47 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch (15.85 KB, patch)
2017-12-08 15:35 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (3.39 MB, application/zip)
2017-12-08 16:55 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews126 for ios-simulator-wk2 (8.36 MB, application/zip)
2017-12-08 17:03 PST, EWS Watchlist
no flags Details
Patch (15.81 KB, patch)
2017-12-08 18:03 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2017-12-07 22:59:17 PST
Delay many service worker operations until after the database import completes

This is so pages don't stomp over existing registrations, so fetches from service workers will happen, etc etc.
Comment 1 Brady Eidson 2017-12-07 23:15:00 PST
Created attachment 328794 [details]
Patch

Bedtime ZzZzzzzzz
Comment 2 EWS Watchlist 2017-12-08 00:41:32 PST
Comment on attachment 328794 [details]
Patch

Attachment 328794 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/5540326

New failing tests:
storage/indexeddb/pending-version-change-on-exit-private.html
http/tests/contentextensions/top-url.html
storage/indexeddb/pending-version-change-stuck-works-with-terminate-private.html
storage/indexeddb/pending-version-change-stuck-private.html
http/tests/cache-storage/cache-persistency.https.html
http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html
http/tests/workers/service/basic-register.html
storage/indexeddb/open-bad-versions-private.html
http/tests/cache-storage/cache-representation.https.html
http/tests/security/cookies/third-party-cookie-blocking-redirect.html
animations/3d/change-transform-in-end-event.html
storage/domstorage/localstorage/private-browsing-affects-storage.html
storage/indexeddb/dont-wedge-private.html
storage/indexeddb/modern/transactions-stop-on-navigation-private.html
Comment 3 EWS Watchlist 2017-12-08 00:41:34 PST
Created attachment 328796 [details]
Archive of layout-test-results from ews104 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 4 EWS Watchlist 2017-12-08 01:36:44 PST
Comment on attachment 328794 [details]
Patch

Attachment 328794 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5540312

New failing tests:
http/tests/security/cookies/third-party-cookie-blocking.html
http/tests/security/cookies/third-party-cookie-blocking-xslt.xml
http/tests/cache-storage/cache-persistency.https.html
http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html
http/tests/security/cookies/third-party-cookie-blocking-redirect.html
http/tests/cache-storage/cache-representation.https.html
http/tests/security/cookies/third-party-cookie-blocking-main-frame.html
http/tests/workers/service/basic-register.html
storage/domstorage/localstorage/private-browsing-affects-storage.html
http/tests/security/cookies/first-party-cookie-allow-xslt.xml
Comment 5 EWS Watchlist 2017-12-08 01:36:47 PST
Created attachment 328798 [details]
Archive of layout-test-results from ews124 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews124  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 6 Brady Eidson 2017-12-08 09:18:39 PST
The Mac WK2 failures appear to be something systemically wrong with the bot that was running things - We were seeing Cache tests fail, IDB tests fail, and content blocker extensions failing to compile... all things that this patch didn't touch.
Comment 7 Brady Eidson 2017-12-08 09:19:51 PST
(In reply to Brady Eidson from comment #6)
> The Mac WK2 failures appear to be something systemically wrong with the bot
> that was running things - We were seeing Cache tests fail, IDB tests fail,
> and content blocker extensions failing to compile... all things that this
> patch didn't touch.

The iOS-sim failures were suspiciously similar =/

Building and running these locally...
Comment 8 Brady Eidson 2017-12-08 12:22:19 PST
Created attachment 328852 [details]
Patch
Comment 9 Brady Eidson 2017-12-08 12:24:36 PST
The failures were probably because of the "multiple WKTR's sharing the same database file" bug that was just resolved.
Comment 10 Chris Dumez 2017-12-08 13:41:18 PST
Comment on attachment 328852 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=328852&action=review

> Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:71
> +    if (!m_isImported)

As soon as you start adding origins to the store, WebSWOriginStore::didInvalidateSharedMemory() will be called and it will send the store handle to the WebProcesses, which I guess is not want you want.
Comment 11 Chris Dumez 2017-12-08 13:44:27 PST
Comment on attachment 328852 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=328852&action=review

> Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:79
>      sendStoreHandle(connection);

Also, what makes sure you send the store handle to the Webprocesses once the import is complete (since you exit early earlier when !m_isImported).
Comment 12 Chris Dumez 2017-12-08 13:59:04 PST
Comment on attachment 328852 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=328852&action=review

>> Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:71
>> +    if (!m_isImported)
> 
> As soon as you start adding origins to the store, WebSWOriginStore::didInvalidateSharedMemory() will be called and it will send the store handle to the WebProcesses, which I guess is not want you want.

As commented offline, it seems fine after all to send the storeHandle() before the import is complete. However, there is still an issue when:
1. Import is in progress and we already have some data in the table
2. WebProcess A starts and WebSWOriginStore::registerSWServerConnection() is called
  -> Does not send the store handle
3. Import is now complete and importComplete() is called.
  -> We send SetSWOriginTableIsImported IPC to WebProcess A but it may not have gotten the store handle.
Comment 13 Brady Eidson 2017-12-08 14:05:41 PST
Created attachment 328867 [details]
Patch
Comment 14 Chris Dumez 2017-12-08 14:07:52 PST
Note that your recent patch iteration had the same timeouts:
Regressions: Unexpected timeouts (12)
  http/tests/cache-storage/cache-persistency.https.html [ Timeout ]
  http/tests/cache-storage/cache-representation.https.html [ Timeout ]
  http/tests/security/cookies/third-party-cookie-blocking-redirect.html [ Timeout ]
  http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html [ Timeout ]
  http/tests/workers/service/basic-register.html [ Timeout ]
  storage/domstorage/localstorage/private-browsing-affects-storage.html [ Timeout ]
  storage/indexeddb/dont-wedge-private.html [ Timeout ]
  storage/indexeddb/modern/transactions-stop-on-navigation-private.html [ Timeout ]
  storage/indexeddb/open-bad-versions-private.html [ Timeout ]
  storage/indexeddb/pending-version-change-on-exit-private.html [ Timeout ]
  storage/indexeddb/pending-version-change-stuck-private.html [ Timeout ]
  storage/indexeddb/pending-version-change-stuck-works-with-terminate-private.html [ Timeout ]

They may not be fixed after all?
Comment 15 Chris Dumez 2017-12-08 14:18:44 PST
Comment on attachment 328867 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=328867&action=review

> Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:79
> +    connection.send(Messages::WebSWClientConnection::SetSWOriginTableIsImported());

If m_store.isEmpty() but m_isImported is true, I believe we want to send the SetSWOriginTableIsImported IPC instead of merely returning early. Otherwise, the WebProcess will keep querying the StorageProcess even though there are no service workers and the import is done.

> Source/WebKit/WebProcess/Storage/WebSWClientConnection.h:93
> +    void runOrDelayTask(WTF::Function<void()>&& task);

Nit: It'd be nice if the name indicated the reason for delaying. Alternatively, it might look nicer to make mayHaveServiceWorkerRegisteredForOrigin() take in a lambda instead.
Comment 16 Brady Eidson 2017-12-08 14:47:46 PST
Created attachment 328873 [details]
Patch
Comment 17 Brady Eidson 2017-12-08 14:48:19 PST
Didn't try to fix the tests in this new patch - Exploring if I can reproduce them locally
Comment 18 Brady Eidson 2017-12-08 15:02:45 PST
COOL: Just http/tests/cache-storage/cache-persistency.https.html by itself timeouts
Comment 19 Brady Eidson 2017-12-08 15:03:27 PST
Yup, private browsing vs the database! Nice.

ServiceWorker RegistrationDatabase opening file /var/folders/py/zsbx8whs03ngn_1kynm1ngph0000gn/T/WebKitTestRunners-JLXrgN/ServiceWorkers/ServiceWorkerRegistrations.sqlite3
ServiceWorker RegistrationDatabase opening file /ServiceWorkerRegistrations.sqlite3
ERROR: SQLite database failed to load from /ServiceWorkerRegistrations.sqlite3
Cause - unable to open database file
/Volumes/Data/git/OpenSource/Source/WebCore/platform/sql/SQLiteDatabase.cpp(90) : bool WebCore::SQLiteDatabase::open(const WTF::String &, bool)
Wait on notifyDone timed out, process com.apple.WebKit.WebContent.Development pid = 17358#EOF
Comment 20 Brady Eidson 2017-12-08 15:04:00 PST
These private browsing things are already occurring... but now activity is delayed as a result.
Comment 21 Brady Eidson 2017-12-08 15:35:20 PST
Created attachment 328879 [details]
Patch
Comment 22 Chris Dumez 2017-12-08 15:43:39 PST
Comment on attachment 328879 [details]
Patch

r=me if the bots are happy.
Comment 23 Brady Eidson 2017-12-08 16:51:42 PST
(In reply to Chris Dumez from comment #22)
> Comment on attachment 328879 [details]
> Patch
> 
> r=me if the bots are happy.

The bots are not happy, but I also can't successfully run tests locally, without my patch, without the same failures... somethings rotten
Comment 24 EWS Watchlist 2017-12-08 16:55:08 PST
Comment on attachment 328879 [details]
Patch

Attachment 328879 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/5552888

New failing tests:
http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html
Comment 25 EWS Watchlist 2017-12-08 16:55:10 PST
Created attachment 328885 [details]
Archive of layout-test-results from ews104 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 26 Brady Eidson 2017-12-08 17:01:51 PST
I think it's a mis-merge after https://trac.webkit.org/changeset/225711/webkit landed. ugh.
Comment 27 EWS Watchlist 2017-12-08 17:03:37 PST
Comment on attachment 328879 [details]
Patch

Attachment 328879 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5552797

New failing tests:
http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html
Comment 28 EWS Watchlist 2017-12-08 17:03:39 PST
Created attachment 328888 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 29 Chris Dumez 2017-12-08 17:42:28 PST
(In reply to Build Bot from comment #27)
> Comment on attachment 328879 [details]
> Patch
> 
> Attachment 328879 [details] did not pass ios-sim-ews (ios-simulator-wk2):
> Output: http://webkit-queues.webkit.org/results/5552797
> 
> New failing tests:
> http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html

It is timing out.
Comment 30 Chris Dumez 2017-12-08 17:48:49 PST
(In reply to Chris Dumez from comment #29)
> (In reply to Build Bot from comment #27)
> > Comment on attachment 328879 [details]
> > Patch
> > 
> > Attachment 328879 [details] did not pass ios-sim-ews (ios-simulator-wk2):
> > Output: http://webkit-queues.webkit.org/results/5552797
> > 
> > New failing tests:
> > http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html
> 
> It is timing out.

The test in question is calling getRegistration() from a ServiceWorker, which ends up calling matchRegistration() that you modified. Presumably, the request gets queued up due to import and never processed?
Comment 31 Chris Dumez 2017-12-08 17:53:42 PST
(In reply to Chris Dumez from comment #30)
> (In reply to Chris Dumez from comment #29)
> > (In reply to Build Bot from comment #27)
> > > Comment on attachment 328879 [details]
> > > Patch
> > > 
> > > Attachment 328879 [details] did not pass ios-sim-ews (ios-simulator-wk2):
> > > Output: http://webkit-queues.webkit.org/results/5552797
> > > 
> > > New failing tests:
> > > http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html
> > 
> > It is timing out.
> 
> The test in question is calling getRegistration() from a ServiceWorker,
> which ends up calling matchRegistration() that you modified. Presumably, the
> request gets queued up due to import and never processed?

I can reproduce the time out locally:
Tools/Scripts/run-webkit-tests --no-retry http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html
Comment 32 Chris Dumez 2017-12-08 17:57:25 PST
Comment on attachment 328879 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=328879&action=review

> Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp:155
> +    runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL]() mutable {

I added some logging locally, I see us calling runOrDelayTaskForImport() here but the lambda is never called.
Comment 33 Chris Dumez 2017-12-08 18:02:14 PST
Comment on attachment 328879 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=328879&action=review

> Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:74
> +    if (m_isImported)

This is never set to true?
Comment 34 Chris Dumez 2017-12-08 18:03:41 PST
Created attachment 328893 [details]
Patch
Comment 35 Chris Dumez 2017-12-08 18:04:24 PST
Comment on attachment 328893 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=328893&action=review

> Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:63
> +    m_isImported = true;

Setting m_isImported to true here fixes the issue for me locally.
Comment 36 Brady Eidson 2017-12-08 18:40:27 PST
(In reply to Chris Dumez from comment #35)
> Comment on attachment 328893 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=328893&action=review
> 
> > Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:63
> > +    m_isImported = true;
> 
> Setting m_isImported to true here fixes the issue for me locally.

Yup, I had just sprinkled logging around that before having to leave the office, didn't quite finish proving it.

That fixes http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html, does it fix the others?
Comment 37 Chris Dumez 2017-12-08 18:42:56 PST
(In reply to Brady Eidson from comment #36)
> (In reply to Chris Dumez from comment #35)
> > Comment on attachment 328893 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=328893&action=review
> > 
> > > Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp:63
> > > +    m_isImported = true;
> > 
> > Setting m_isImported to true here fixes the issue for me locally.
> 
> Yup, I had just sprinkled logging around that before having to leave the
> office, didn't quite finish proving it.
> 
> That fixes
> http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html,
> does it fix the others?

Last EWS round had only http/tests/workers/service/ServiceWorkerGlobalScope_getRegistration.html failing.
Comment 38 Brady Eidson 2017-12-08 18:52:58 PST
Awesome. So thinking about that the symptom and fix totally fit with each other.

Thanks for following up while I was stuck in traffic. :)
Comment 39 Chris Dumez 2017-12-08 18:55:14 PST
(In reply to Brady Eidson from comment #38)
> Awesome. So thinking about that the symptom and fix totally fit with each
> other.
> 
> Thanks for following up while I was stuck in traffic. :)

No problem. Please make sure the radar is updated.
Comment 40 WebKit Commit Bot 2017-12-08 19:03:10 PST
Comment on attachment 328893 [details]
Patch

Clearing flags on attachment: 328893

Committed r225717: <https://trac.webkit.org/changeset/225717>
Comment 41 WebKit Commit Bot 2017-12-08 19:03:12 PST
All reviewed patches have been landed.  Closing bug.