Bug 235958 - Add support for sharing Shared Workers (including across WebProcesses)
Summary: Add support for sharing Shared Workers (including across WebProcesses)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on: 235978 235983 235987 235988 236016 236017 236026 236028 236038 236052 236085 236088 236089 236101
Blocks: 230382
  Show dependency treegraph
 
Reported: 2022-02-01 09:01 PST by Chris Dumez
Modified: 2022-02-22 15:00 PST (History)
19 users (show)

See Also:


Attachments
WIP Patch (281.88 KB, patch)
2022-02-01 09:03 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (300.46 KB, patch)
2022-02-01 11:00 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (303.17 KB, patch)
2022-02-01 11:35 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (321.56 KB, patch)
2022-02-01 13:18 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (321.50 KB, patch)
2022-02-01 14:05 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (330.07 KB, patch)
2022-02-01 15:25 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (314.22 KB, patch)
2022-02-01 19:04 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (314.41 KB, patch)
2022-02-01 22:09 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (322.41 KB, patch)
2022-02-02 09:53 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (321.45 KB, patch)
2022-02-02 11:48 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (317.74 KB, patch)
2022-02-02 11:53 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (309.24 KB, patch)
2022-02-02 12:47 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (310.06 KB, patch)
2022-02-02 13:31 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (307.07 KB, patch)
2022-02-02 16:09 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (293.78 KB, patch)
2022-02-02 18:55 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (251.22 KB, patch)
2022-02-03 09:13 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (262.26 KB, patch)
2022-02-03 10:39 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (257.08 KB, patch)
2022-02-03 11:43 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (253.79 KB, patch)
2022-02-03 12:22 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (297.48 KB, patch)
2022-02-03 13:05 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (301.56 KB, patch)
2022-02-03 15:17 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (310.65 KB, patch)
2022-02-03 17:11 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP Patch (268.23 KB, patch)
2022-02-04 09:34 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (288.33 KB, patch)
2022-02-04 11:28 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (290.60 KB, patch)
2022-02-04 12:05 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (296.29 KB, patch)
2022-02-04 13:28 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (298.21 KB, patch)
2022-02-04 15:24 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (311.50 KB, patch)
2022-02-04 17:02 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (316.35 KB, patch)
2022-02-07 08:21 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (316.28 KB, patch)
2022-02-07 12:11 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 Chris Dumez 2022-02-01 09:01:00 PST
Add support for sharing Shared Workers (including across WebProcesses).
Comment 1 Radar WebKit Bug Importer 2022-02-01 09:01:25 PST
<rdar://problem/88330666>
Comment 2 Chris Dumez 2022-02-01 09:03:23 PST
Created attachment 450537 [details]
WIP Patch
Comment 3 Chris Dumez 2022-02-01 11:00:48 PST
Created attachment 450548 [details]
WIP Patch
Comment 4 Chris Dumez 2022-02-01 11:35:34 PST
Created attachment 450554 [details]
WIP Patch
Comment 5 Chris Dumez 2022-02-01 13:18:35 PST
Created attachment 450561 [details]
WIP Patch
Comment 6 Chris Dumez 2022-02-01 14:05:07 PST
Created attachment 450565 [details]
WIP Patch
Comment 7 Chris Dumez 2022-02-01 15:25:12 PST
Created attachment 450581 [details]
WIP Patch
Comment 8 Chris Dumez 2022-02-01 16:43:57 PST
The patch is huge so I'll try and split parts of it out to facilitate review a bit.
Comment 9 Chris Dumez 2022-02-01 19:04:54 PST
Created attachment 450602 [details]
WIP Patch
Comment 10 Chris Dumez 2022-02-01 22:09:56 PST
Created attachment 450610 [details]
WIP Patch
Comment 11 Chris Dumez 2022-02-02 09:53:53 PST
Created attachment 450662 [details]
WIP Patch
Comment 12 Chris Dumez 2022-02-02 11:48:53 PST
Created attachment 450683 [details]
WIP Patch
Comment 13 Chris Dumez 2022-02-02 11:53:11 PST
Created attachment 450684 [details]
WIP Patch
Comment 14 Chris Dumez 2022-02-02 12:47:11 PST
Created attachment 450691 [details]
WIP Patch
Comment 15 Chris Dumez 2022-02-02 13:31:43 PST
Created attachment 450694 [details]
WIP Patch
Comment 16 Chris Dumez 2022-02-02 16:09:30 PST
Created attachment 450710 [details]
WIP Patch
Comment 17 Chris Dumez 2022-02-02 18:55:22 PST
Created attachment 450727 [details]
WIP Patch
Comment 18 Chris Dumez 2022-02-03 09:13:25 PST
Created attachment 450777 [details]
WIP Patch
Comment 19 Chris Dumez 2022-02-03 10:39:15 PST
Created attachment 450791 [details]
WIP Patch
Comment 20 Chris Dumez 2022-02-03 11:43:21 PST
Created attachment 450801 [details]
WIP Patch
Comment 21 Chris Dumez 2022-02-03 12:22:50 PST
Created attachment 450803 [details]
WIP Patch
Comment 22 Chris Dumez 2022-02-03 13:05:50 PST
Created attachment 450806 [details]
WIP Patch
Comment 23 Chris Dumez 2022-02-03 15:17:57 PST
Created attachment 450829 [details]
WIP Patch
Comment 24 Chris Dumez 2022-02-03 17:11:31 PST
Created attachment 450840 [details]
WIP Patch
Comment 25 Chris Dumez 2022-02-04 09:34:45 PST
Created attachment 450906 [details]
WIP Patch
Comment 26 Chris Dumez 2022-02-04 11:28:23 PST
Created attachment 450921 [details]
Patch
Comment 27 Chris Dumez 2022-02-04 12:05:31 PST
Created attachment 450928 [details]
Patch
Comment 28 Chris Dumez 2022-02-04 13:28:44 PST
Created attachment 450934 [details]
Patch
Comment 29 Chris Dumez 2022-02-04 15:24:11 PST
Created attachment 450943 [details]
Patch
Comment 30 Chris Dumez 2022-02-04 17:02:16 PST
Created attachment 450954 [details]
Patch
Comment 31 Darin Adler 2022-02-05 22:42:48 PST
Comment on attachment 450954 [details]
Patch

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

Looks good, I didn’t spot any mistakes.

> Source/WebCore/workers/shared/SharedWorkerKey.h:52
> +    Hasher hasher;
> +    add(hasher, origin.hash());
> +    add(hasher, url);
> +    add(hasher, name);
> +    return hasher.hash();

Instead, we should write:

    return computeHash(origin.hash(), url, name);

That does the same thing. But also, it’s not good to hash a hash. Instead, we should write these functions:

    inline add(Hasher& hasher, const SharedWorkerKey& key)
    {
        hasher.add(key.origin, key.url, key.name);
    }
    inline add(Hasher& hasher, const ClientOrigin& origin)
    {
        add(hasher, origin.topOrigin, origin.clientOrigin);
    }
    inline add(Hasher& hasher, const SecurityOriginData& data)
    {
        add(hasher, data.protocol, data.host, data.port);
    }

These don’t have to be inlined, and of course they should go in the appropriate headers. Once those functions are all defined, we can call computeHash on any of these types, without any hashing of a hash getting involved. If we want, we can still define SharedWorkerKey::hash, but it should just call computeHash:

    unsigned hash() const { return computeHash(*this); }
Comment 32 Darin Adler 2022-02-05 22:43:37 PST
Forgot the "void" above:

    inline void add ...

But otherwise the code should work.
Comment 33 Chris Dumez 2022-02-07 08:21:54 PST
Created attachment 451107 [details]
Patch
Comment 34 Chris Dumez 2022-02-07 10:36:32 PST
Hmm, http/tests/cache-storage/cache-origins.https.html appears to be failing on EWS. I'll have to investigate. It is not involving Shared Workers but maybe I messed up the new hash functions somehow.
Comment 35 Darin Adler 2022-02-07 11:06:01 PST
Comment on attachment 451107 [details]
Patch

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

> Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h:32
> +#include <wtf/Hasher.h>
>  #include <wtf/text/StringHash.h>
>  #include <wtf/text/WTFString.h>

We don’t need any of these includes. ClientOrigin.h already pulls them in (I’m not sure about StringHash, but if it’s needed it’s pulled in).

> Source/WebCore/page/SecurityOriginData.h:103
> +    add(hasher, data.protocol, data.host, data.port);

If we wanted to more closely match the old hash function, this would need to be data.port.value_or(0) unless we want "no port" to hash differently than a port number. We probably do want them distinct just the way this is written, but I noticed it is a difference.

> Source/WebCore/workers/shared/SharedWorkerKey.h:31
> +#include <wtf/Hasher.h>
> +#include <wtf/URL.h>
> +#include <wtf/text/WTFString.h>

Don’t need this any of these. They are all included by ClientOrigin.h already.
Comment 36 Chris Dumez 2022-02-07 12:11:12 PST
Created attachment 451136 [details]
Patch
Comment 37 Chris Dumez 2022-02-07 12:11:52 PST
(In reply to Darin Adler from comment #35)
> Comment on attachment 451107 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451107&action=review
> 
> > Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h:32
> > +#include <wtf/Hasher.h>
> >  #include <wtf/text/StringHash.h>
> >  #include <wtf/text/WTFString.h>
> 
> We don’t need any of these includes. ClientOrigin.h already pulls them in
> (I’m not sure about StringHash, but if it’s needed it’s pulled in).
> 
> > Source/WebCore/page/SecurityOriginData.h:103
> > +    add(hasher, data.protocol, data.host, data.port);
> 
> If we wanted to more closely match the old hash function, this would need to
> be data.port.value_or(0) unless we want "no port" to hash differently than a
> port number. We probably do want them distinct just the way this is written,
> but I noticed it is a difference.

It appears this was the cause of the regression, thanks!
Comment 38 Darin Adler 2022-02-07 12:16:23 PST
Comment on attachment 451107 [details]
Patch

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

>> Source/WebCore/page/SecurityOriginData.h:103
>> +    add(hasher, data.protocol, data.host, data.port);
> 
> If we wanted to more closely match the old hash function, this would need to be data.port.value_or(0) unless we want "no port" to hash differently than a port number. We probably do want them distinct just the way this is written, but I noticed it is a difference.

You said this caused the regression. That is very mysterious! Because the == operator does not treat std::nullopt as equal to 0, so it should not matter whether the hash function does or not!
Comment 39 Chris Dumez 2022-02-07 12:29:35 PST
(In reply to Darin Adler from comment #38)
> Comment on attachment 451107 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451107&action=review
> 
> >> Source/WebCore/page/SecurityOriginData.h:103
> >> +    add(hasher, data.protocol, data.host, data.port);
> > 
> > If we wanted to more closely match the old hash function, this would need to be data.port.value_or(0) unless we want "no port" to hash differently than a port number. We probably do want them distinct just the way this is written, but I noticed it is a difference.
> 
> You said this caused the regression. That is very mysterious! Because the ==
> operator does not treat std::nullopt as equal to 0, so it should not matter
> whether the hash function does or not!

My bet is that this has to do with conversion of SecurityOriginData to and from String. In particular, the databaseIdentifier() / fromDatabaseIdentifier() implementation seem to treat a port that is 0 the same way has not having a port.
Comment 40 Darin Adler 2022-02-07 12:45:07 PST
Still kind of mysterious, because in any context where we are converting to a string, then we should be hashing the string.
Comment 41 Chris Dumez 2022-02-07 12:57:40 PST
(In reply to Darin Adler from comment #40)
> Still kind of mysterious, because in any context where we are converting to
> a string, then we should be hashing the string.

What I meant was:
1. Add a SecurityOriginData S1 "http://foo:0" to a HashMap H
2. Convert the SecurityOriginData S1 to a database identifier and save in database
3. Read identifier from database and convert back to a SecurityOriginData S2 "http://foo" (because fromDatabaseIdentifier() strips the port).
4. Check if S2 is present in HashMap H -> Says false (should probably say true?)

That said, because operator==(S1, S2) would say false before and after my change, then it should say S2 is not in the map, even if the hashes for S1 and S2 were to match...

I am perplexed too.
Comment 42 Chris Dumez 2022-02-07 14:16:01 PST
(In reply to Chris Dumez from comment #41)
> (In reply to Darin Adler from comment #40)
> > Still kind of mysterious, because in any context where we are converting to
> > a string, then we should be hashing the string.
> 
> What I meant was:
> 1. Add a SecurityOriginData S1 "http://foo:0" to a HashMap H
> 2. Convert the SecurityOriginData S1 to a database identifier and save in
> database
> 3. Read identifier from database and convert back to a SecurityOriginData S2
> "http://foo" (because fromDatabaseIdentifier() strips the port).
> 4. Check if S2 is present in HashMap H -> Says false (should probably say
> true?)
> 
> That said, because operator==(S1, S2) would say false before and after my
> change, then it should say S2 is not in the map, even if the hashes for S1
> and S2 were to match...
> 
> I am perplexed too.

I added some logging and we never hash a SecurityOriginData that has a port that is 0. All security origins getting hashed have a valid port, except for "file://" which has no port. Haven't had any success figuring out yet why the value_or(0) is needed but it is definitely what fixes the test.
Comment 43 Chris Dumez 2022-02-07 14:53:33 PST
Oh, I think I got it. The hashing is actually correct either way. What changes is the order of keys in the map (map of ClientOrigin keys). http/tests/cache-storage/cache-origins.https.html seems to rely on a specific ordering and needs to be fixed.
Comment 44 Darin Adler 2022-02-07 15:06:43 PST
(In reply to Chris Dumez from comment #43)
> http/tests/cache-storage/cache-origins.https.html seems to rely on a
> specific ordering and needs to be fixed.

Yes, WebKit::CacheStorage::Engine::representation needs to add things to the string in an order not based on hash table ordering.
Comment 45 Darin Adler 2022-02-07 15:07:10 PST
Move the data into an array, sort the array, then build the string, I think.
Comment 46 Chris Dumez 2022-02-07 15:07:45 PST
(In reply to Darin Adler from comment #45)
> Move the data into an array, sort the array, then build the string, I think.

I uploaded a proposal at https://bugs.webkit.org/show_bug.cgi?id=236263. Just fixing the test.
Comment 47 Chris Dumez 2022-02-07 16:19:09 PST
Comment on attachment 451136 [details]
Patch

Clearing flags on attachment: 451136

Committed r289247 (246931@trunk): <https://commits.webkit.org/246931@trunk>
Comment 48 Chris Dumez 2022-02-07 16:19:14 PST
All reviewed patches have been landed.  Closing bug.
Comment 49 Jonathan Bedard 2022-02-22 15:00:02 PST
https://results.webkit.org/?suite=layout-tests&test=imported%2Fw3c%2Fweb-platform-tests%2Fworkers%2Fsemantics%2Fmultiple-workers%2F004.html indicates that 246931@main caused imported/w3c/web-platform-tests/workers/semantics/multiple-workers/004.html to start flakily failing.