Bug 239122 - Shared workers should match service worker registrations
Summary: Shared workers should match service worker registrations
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: 239066
Blocks:
  Show dependency treegraph
 
Reported: 2022-04-12 05:37 PDT by youenn fablet
Modified: 2022-04-27 01:22 PDT (History)
7 users (show)

See Also:


Attachments
Patch (65.04 KB, patch)
2022-04-12 05:40 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (65.56 KB, patch)
2022-04-14 02:30 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (66.11 KB, patch)
2022-04-14 06:24 PDT, youenn fablet
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (68.55 KB, patch)
2022-04-14 08:17 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (68.65 KB, patch)
2022-04-15 00:17 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (67.47 KB, patch)
2022-04-21 06:37 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Fix remote worker process change (80.23 KB, patch)
2022-04-22 03:14 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Fix remote worker process change (80.23 KB, patch)
2022-04-22 05:56 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Rebasing (80.45 KB, patch)
2022-04-22 07:15 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (81.77 KB, patch)
2022-04-26 02:37 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Rebasing (81.81 KB, patch)
2022-04-26 04:52 PDT, youenn fablet
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Fix build (81.83 KB, patch)
2022-04-26 05:04 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Fix WinCairo (81.94 KB, patch)
2022-04-26 23:17 PDT, youenn fablet
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Fix WinCairo (81.95 KB, patch)
2022-04-26 23:52 PDT, 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 2022-04-12 05:37:07 PDT
Shared workers should match service worker registrations
Comment 1 youenn fablet 2022-04-12 05:40:37 PDT
Created attachment 457327 [details]
Patch
Comment 2 youenn fablet 2022-04-14 02:30:15 PDT
Created attachment 457605 [details]
Patch
Comment 3 youenn fablet 2022-04-14 06:24:32 PDT
Created attachment 457619 [details]
Patch
Comment 4 youenn fablet 2022-04-14 08:17:23 PDT
Created attachment 457631 [details]
Patch
Comment 5 youenn fablet 2022-04-15 00:17:09 PDT
Created attachment 457680 [details]
Patch
Comment 6 Chris Dumez 2022-04-15 07:32:16 PDT
Comment on attachment 457680 [details]
Patch

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

r=me

> Source/WebCore/workers/service/SWClientConnection.cpp:134
> +        worker->postTaskToWorkerGlobalScope([message = WTFMove(message), sourceData = WTFMove(sourceData), sourceOrigin = WTFMove(sourceOrigin).isolatedCopy()] (auto& context) mutable {

WTFMove(sourceData).isolatedCopy()

Let the optimization in `ServiceWorkerData isolatedCopy() &&;` determine if moving is safe.

> Source/WebCore/workers/service/SWClientConnection.cpp:141
> +        sharedWorker->thread().runLoop().postTask([message = WTFMove(message), sourceData = WTFMove(sourceData), sourceOrigin = WTFMove(sourceOrigin).isolatedCopy()] (auto& context) mutable {

WTFMove(sourceData).isolatedCopy()

> Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp:54
> +    static NeverDestroyed<HashMap<ScriptExecutionContextIdentifier, SharedWorkerThreadProxy*>> map;

Should probably use MainThreadNeverDestroyed.

> Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp:93
> +    , m_clientIdentifier(*initializationData.clientIdentifier)

use-after-move of initializationData. While this may work in practice, it looks unsafe and should be avoided.

> Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h:88
> +    ScriptExecutionContextIdentifier m_clientIdentifier;

I am a bit unclear about what this means. A sharedWorker doesn't necessarily have a single client.
Comment 7 youenn fablet 2022-04-15 07:53:54 PDT
> > Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp:93
> > +    , m_clientIdentifier(*initializationData.clientIdentifier)
> 
> use-after-move of initializationData. While this may work in practice, it
> looks unsafe and should be avoided.
> 
> > Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h:88
> > +    ScriptExecutionContextIdentifier m_clientIdentifier;
> 
> I am a bit unclear about what this means. A sharedWorker doesn't necessarily
> have a single client.

It is the id of the shared worker context, exposed as client.id.
Comment 8 Chris Dumez 2022-04-15 07:59:32 PDT
(In reply to youenn fablet from comment #7)
> > > Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp:93
> > > +    , m_clientIdentifier(*initializationData.clientIdentifier)
> > 
> > use-after-move of initializationData. While this may work in practice, it
> > looks unsafe and should be avoided.
> > 
> > > Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h:88
> > > +    ScriptExecutionContextIdentifier m_clientIdentifier;
> > 
> > I am a bit unclear about what this means. A sharedWorker doesn't necessarily
> > have a single client.
> 
> It is the id of the shared worker context, exposed as client.id.

I see but the naming is confusing in the context of a shared worker when we say "client". I thought you meant client of the shared worker. When you meant that the shared worker is the client of the service worker. Not sure how to clarify though.
Comment 9 Chris Dumez 2022-04-15 08:00:08 PDT
(In reply to Chris Dumez from comment #8)
> (In reply to youenn fablet from comment #7)
> > > > Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp:93
> > > > +    , m_clientIdentifier(*initializationData.clientIdentifier)
> > > 
> > > use-after-move of initializationData. While this may work in practice, it
> > > looks unsafe and should be avoided.
> > > 
> > > > Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h:88
> > > > +    ScriptExecutionContextIdentifier m_clientIdentifier;
> > > 
> > > I am a bit unclear about what this means. A sharedWorker doesn't necessarily
> > > have a single client.
> > 
> > It is the id of the shared worker context, exposed as client.id.
> 
> I see but the naming is confusing in the context of a shared worker when we
> say "client". I thought you meant client of the shared worker. When you
> meant that the shared worker is the client of the service worker. Not sure
> how to clarify though.

Maybe it should be m_contextIdentifier?
Comment 10 Radar WebKit Bug Importer 2022-04-19 05:38:12 PDT
<rdar://problem/91954369>
Comment 11 youenn fablet 2022-04-21 03:16:18 PDT
> Maybe it should be m_contextIdentifier?

Sounds good.
Comment 12 youenn fablet 2022-04-21 06:37:10 PDT
Created attachment 458056 [details]
Patch for landing
Comment 13 youenn fablet 2022-04-22 03:14:37 PDT
Created attachment 458130 [details]
Fix remote worker process change
Comment 14 youenn fablet 2022-04-22 05:56:13 PDT
Created attachment 458139 [details]
Fix remote worker process change
Comment 15 youenn fablet 2022-04-22 07:15:37 PDT
Created attachment 458144 [details]
Rebasing
Comment 16 youenn fablet 2022-04-26 02:37:40 PDT
Created attachment 458347 [details]
Patch
Comment 17 youenn fablet 2022-04-26 04:52:54 PDT
Created attachment 458351 [details]
Rebasing
Comment 18 youenn fablet 2022-04-26 05:04:00 PDT
Created attachment 458353 [details]
Fix build
Comment 19 youenn fablet 2022-04-26 23:17:55 PDT
Created attachment 458420 [details]
Fix WinCairo
Comment 20 youenn fablet 2022-04-26 23:52:10 PDT
Created attachment 458423 [details]
Fix WinCairo
Comment 21 EWS 2022-04-27 01:22:32 PDT
Committed r293501 (250032@main): <https://commits.webkit.org/250032@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 458423 [details].