Bug 179480 - matchRegistration does not need to go to StorageProcess if no service worker is registered
Summary: matchRegistration does not need to go to StorageProcess if no service worker ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-11-09 08:41 PST by youenn fablet
Modified: 2017-12-04 07:59 PST (History)
8 users (show)

See Also:


Attachments
Patch (2.09 KB, patch)
2017-11-09 08:42 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-elcapitan-wk2 (2.86 MB, application/zip)
2017-11-09 09:56 PST, Build Bot
no flags Details
Archive of layout-test-results from ews122 for ios-simulator-wk2 (2.24 MB, application/zip)
2017-11-09 10:06 PST, Build Bot
no flags Details
Patch (11.01 KB, patch)
2017-11-09 16:15 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (16.09 KB, patch)
2017-11-09 17:20 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (21.12 KB, patch)
2017-11-12 22:38 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (21.14 KB, patch)
2017-11-13 09:55 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (24.39 KB, patch)
2017-11-13 13:19 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (32.63 KB, patch)
2017-11-13 14:45 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (32.62 KB, patch)
2017-11-13 14:47 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (32.35 KB, patch)
2017-11-13 15:26 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2017-11-09 08:41:27 PST
This is a small optimization
Comment 1 youenn fablet 2017-11-09 08:42:39 PST
Created attachment 326451 [details]
Patch
Comment 2 Build Bot 2017-11-09 09:56:45 PST
Comment on attachment 326451 [details]
Patch

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

New failing tests:
imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https.html
http/tests/workers/service/service-worker-getRegistration.html
imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html
Comment 3 Build Bot 2017-11-09 09:56:46 PST
Created attachment 326460 [details]
Archive of layout-test-results from ews106 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 4 Build Bot 2017-11-09 10:06:13 PST
Comment on attachment 326451 [details]
Patch

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

New failing tests:
http/tests/workers/service/service-worker-getRegistration.html
imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html
Comment 5 Build Bot 2017-11-09 10:06:14 PST
Created attachment 326462 [details]
Archive of layout-test-results from ews122 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews122  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 6 Chris Dumez 2017-11-09 10:53:14 PST
Comment on attachment 326451 [details]
Patch

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

> Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp:111
> +    if (!hasServiceWorkerRegisteredForOrigin(SecurityOrigin::create(clientURL))) {

I think we currently use topOrigin in the store.
Comment 7 youenn fablet 2017-11-09 16:15:40 PST
Created attachment 326505 [details]
Patch
Comment 8 Chris Dumez 2017-11-09 16:28:35 PST
Comment on attachment 326505 [details]
Patch

The new test results look like regression to me. I think we need to investigate them.
Comment 9 youenn fablet 2017-11-09 17:20:30 PST
Created attachment 326516 [details]
Patch
Comment 10 youenn fablet 2017-11-12 22:38:00 PST
Created attachment 326745 [details]
Patch
Comment 11 youenn fablet 2017-11-13 09:55:18 PST
Created attachment 326765 [details]
Patch
Comment 12 Chris Dumez 2017-11-13 12:13:04 PST
Comment on attachment 326765 [details]
Patch

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

> Source/WebCore/workers/service/server/SWServer.cpp:87
> +    if (!m_registrations.set(key, WTFMove(registration)).isNewEntry)

How can it not be a new registration? I think this should be an assertion, not an if check.

> Source/WebCore/workers/service/server/SWServer.cpp:91
> +    ++m_originCounts.ensure(topOrigin->toString(), [&] {

Can we move the originCount to the ServiceWorkerOriginStore for better encapsulation? The server should not have to deal with counts.

> Source/WebCore/workers/service/server/SWServer.cpp:100
> +    if (!m_registrations.remove(key))

I don't think this should happen. Should probably be an assertion instead of an if check.

> Source/WebCore/workers/service/server/SWServer.cpp:120
> +    m_originStore->clear();

I think moving the originStore to SWServer is indeed a good idea.

> LayoutTests/imported/w3c/ChangeLog:8
> +        Updating tests as otherwise they would fail trying to access to document.body which would be null.

How is this related to your code change? You code change is not supposed to cause web-facing behavior change AFAICT. Therefore, no test update should be needed.
Comment 13 youenn fablet 2017-11-13 12:44:29 PST
(In reply to Chris Dumez from comment #12)
> Comment on attachment 326765 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=326765&action=review
> 
> > Source/WebCore/workers/service/server/SWServer.cpp:87
> > +    if (!m_registrations.set(key, WTFMove(registration)).isNewEntry)
> 
> How can it not be a new registration? I think this should be an assertion,
> not an if check.
> 
> > Source/WebCore/workers/service/server/SWServer.cpp:91
> > +    ++m_originCounts.ensure(topOrigin->toString(), [&] {
> 
> Can we move the originCount to the ServiceWorkerOriginStore for better
> encapsulation? The server should not have to deal with counts.
> 
> > Source/WebCore/workers/service/server/SWServer.cpp:100
> > +    if (!m_registrations.remove(key))
> 
> I don't think this should happen. Should probably be an assertion instead of
> an if check.
> 
> > Source/WebCore/workers/service/server/SWServer.cpp:120
> > +    m_originStore->clear();
> 
> I think moving the originStore to SWServer is indeed a good idea.
> 
> > LayoutTests/imported/w3c/ChangeLog:8
> > +        Updating tests as otherwise they would fail trying to access to document.body which would be null.
> 
> How is this related to your code change? You code change is not supposed to
> cause web-facing behavior change AFAICT. Therefore, no test update should be
> needed.

I think there is some race condition between the type document.body is populated and the time the code using document.body is executed. With this additional optimization, we remove an additional IPC call which makes this issue more visible.
Comment 14 youenn fablet 2017-11-13 13:19:19 PST
Created attachment 326786 [details]
Patch
Comment 15 youenn fablet 2017-11-13 13:22:36 PST
> I think there is some race condition between the type document.body is
> populated and the time the code using document.body is executed. With this
> additional optimization, we remove an additional IPC call which makes this
> issue more visible.

I wrapped one of the test with a setTimeout and removed the html body element.
The test then works.
Comment 16 Chris Dumez 2017-11-13 13:27:36 PST
Comment on attachment 326786 [details]
Patch

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

> Source/WebCore/workers/service/server/SWServer.h:113
> +        HashMap<String, uint64_t> m_originCounts;

OriginStore was just supposed to be an interface. We want as much of the store complexity/logic as possible out of SWServer. For this reason, I still believe the counts should be handled at WebSWOriginStore level. WebSWOriginStore basically becomes a HashCountedSet, which is fine.

> LayoutTests/imported/w3c/ChangeLog:7
> +

What's the upstream PR for this change? why is this needed? Where is document.body used? Could not find body being used in activation.https.html, is it used from an imported script or iframe?
Comment 17 Chris Dumez 2017-11-13 13:28:34 PST
(In reply to Chris Dumez from comment #16)
> Comment on attachment 326786 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=326786&action=review
> 
> > Source/WebCore/workers/service/server/SWServer.h:113
> > +        HashMap<String, uint64_t> m_originCounts;
> 
> OriginStore was just supposed to be an interface. We want as much of the
> store complexity/logic as possible out of SWServer. For this reason, I still
> believe the counts should be handled at WebSWOriginStore level.
> WebSWOriginStore basically becomes a HashCountedSet, which is fine.
> 
> > LayoutTests/imported/w3c/ChangeLog:7
> > +
> 
> What's the upstream PR for this change? why is this needed? Where is
> document.body used? Could not find body being used in activation.https.html,
> is it used from an imported script or iframe?

Note that presumably, those tests are passing in Chrome so this may indicate we have a bug?
Comment 18 youenn fablet 2017-11-13 14:45:47 PST
Created attachment 326805 [details]
Patch
Comment 19 youenn fablet 2017-11-13 14:46:08 PST
There is also the case that WebSWOriginTable::contains return false if its origin table shared memory is not yet initialized.
We should probably go to the StorageProcess in that case.

Just trying to tweak it locally and it helps fixing one test, not the other.
But then it makes basic-register.html fail.
I'll fix that as a follow-up.
Comment 20 youenn fablet 2017-11-13 14:47:08 PST
Created attachment 326806 [details]
Patch
Comment 21 Chris Dumez 2017-11-13 15:15:59 PST
Comment on attachment 326806 [details]
Patch

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

r=me with changes.

> Source/WebCore/workers/service/server/SWServer.cpp:88
> +    auto result = m_registrations.set(key, WTFMove(registration));

Should be an add(), not a set(). We should never overwrite.

> Source/WebCore/workers/service/server/SWServer.cpp:115
> +    m_registrations.removeIf([&] (auto& entry) {

We should not make this change unless we also clear the right jobQueues. otherwise, we will end up with jobQueues that are out of sync with the server (expect a registration to be there but isn't).

Let's clear the jobQueues:
m_jobQueues.removeIf([&] (auto& entry) {
    return entry.key.topOrigin() == originData;
});
Comment 22 youenn fablet 2017-11-13 15:26:48 PST
Created attachment 326813 [details]
Patch for landing
Comment 23 WebKit Commit Bot 2017-11-13 16:20:29 PST
Comment on attachment 326813 [details]
Patch for landing

Clearing flags on attachment: 326813

Committed r224792: <https://trac.webkit.org/changeset/224792>
Comment 24 WebKit Commit Bot 2017-11-13 16:20:31 PST
All reviewed patches have been landed.  Closing bug.
Comment 25 youenn fablet 2017-11-14 06:43:05 PST
W3C PR is at https://github.com/w3c/web-platform-tests/pull/8177
Comment 26 Radar WebKit Bug Importer 2017-11-15 09:38:13 PST
<rdar://problem/35562119>
Comment 27 Chris Dumez 2017-12-03 14:48:55 PST
Comment on attachment 326813 [details]
Patch for landing

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

> LayoutTests/imported/w3c/ChangeLog:9
> +        * web-platform-tests/service-workers/service-worker/activation.https.html:

Is there a PR for this? I could not find it.
Comment 28 youenn fablet 2017-12-03 21:00:26 PST
(In reply to Chris Dumez from comment #27)
> Comment on attachment 326813 [details]
> Patch for landing
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=326813&action=review
> 
> > LayoutTests/imported/w3c/ChangeLog:9
> > +        * web-platform-tests/service-workers/service-worker/activation.https.html:
> 
> Is there a PR for this? I could not find it.

This should be https://github.com/w3c/web-platform-tests/pull/8177
Comment 29 Chris Dumez 2017-12-04 07:59:05 PST
(In reply to youenn fablet from comment #28)
> (In reply to Chris Dumez from comment #27)
> > Comment on attachment 326813 [details]
> > Patch for landing
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=326813&action=review
> > 
> > > LayoutTests/imported/w3c/ChangeLog:9
> > > +        * web-platform-tests/service-workers/service-worker/activation.https.html:
> > 
> > Is there a PR for this? I could not find it.
> 
> This should be https://github.com/w3c/web-platform-tests/pull/8177

I see. I got confused because the body is at a different place upstream and downstream.