Bug 182309 - ServiceWorker claim should only succeed if worker is active and running according StorageProcess
Summary: ServiceWorker claim should only succeed if worker is active and running accor...
Status: NEW
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-01-30 14:02 PST by youenn fablet
Modified: 2018-01-30 20:08 PST (History)
3 users (show)

See Also:


Attachments
Patch (14.96 KB, patch)
2018-01-30 16:30 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (16.25 KB, patch)
2018-01-30 18:34 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 2018-01-30 14:02:50 PST
We are only checking in service worker process right now but storage process is the one actually holding the state.
Comment 1 youenn fablet 2018-01-30 15:14:31 PST
<rdar://problem/37004724>
Comment 2 youenn fablet 2018-01-30 16:30:37 PST
Created attachment 332719 [details]
Patch
Comment 3 youenn fablet 2018-01-30 18:34:37 PST
Created attachment 332736 [details]
Patch
Comment 4 Chris Dumez 2018-01-30 19:36:55 PST
Comment on attachment 332736 [details]
Patch

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

> Source/WebCore/workers/service/server/SWServerRegistration.cpp:184
> +    if (iterator != m_clientsUsingRegistration.end()) {

When SWServerRegistration::unregisterServerConnection() is called, we remove that connectionIdentifier from m_clientsUsingRegistration. However, the clients for this connection might still be in SWServer::m_clientToControllingWorker & SWServer::m_clientsById I believe. Thus, the maps get out of sync.

Youenn, do you agree with my analysis?
Comment 5 youenn fablet 2018-01-30 20:08:06 PST
SWServerRegistration::unregisterServerConnection() is called in SWServer::Connection destructor.
Before that, WebSWServerConnection destructor is calling SWServer::unregisterServiceWorkerClient() on all clients of the connection, thus taking care of SWServer::m_clientsById and SWServer::m_clientToControllingWorker.

As a side note, we should probably move WebSWServerConnection::m_clientOrigins back to SWServer::Connection. That would allow doing the whole cleaning in SWServer::Connection destructor.

Given the implementation of SWServer::unregisterServiceWorkerClient(), we may sometimes not call SWServerRegistration::removeClientUsingRegistration since we are trying to get back the registration from the service worker identifier and this only works if the service worker identifier is running or terminating.
There is probably no guarantee that a terminating service worker is kept until all web processes refreshed their ids.

WIP in bug 182313 is trying to fix that issue.