[webkit-changes] [WebKit/WebKit] 76527d: SharedWorkerGlobalScope.close() does not then allo...

Chris Dumez noreply at github.com
Mon Jan 23 11:44:16 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 76527da41c8016eef5fc6f722377cd71f4d7ce47
      https://github.com/WebKit/WebKit/commit/76527da41c8016eef5fc6f722377cd71f4d7ce47
  Author: Chris Dumez <cdumez at apple.com>
  Date:   2023-01-23 (Mon, 23 Jan 2023)

  Changed paths:
    A LayoutTests/http/wpt/shared-workers/relaunch-after-close-expected.txt
    A LayoutTests/http/wpt/shared-workers/relaunch-after-close.html
    A LayoutTests/http/wpt/shared-workers/resources/relaunch-after-close-page2.html
    A LayoutTests/http/wpt/shared-workers/resources/relaunch-after-close-sharedworker.js
    A LayoutTests/http/wpt/shared-workers/resources/relaunch-after-close-window.js
    M Source/WebCore/workers/shared/context/SharedWorkerContextManager.cpp
    M Source/WebCore/workers/shared/context/SharedWorkerContextManager.h
    M Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.cpp
    M Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.h
    M Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp
    M Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.h
    M Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.messages.in
    M Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp
    M Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.h
    M Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.messages.in

  Log Message:
  -----------
  SharedWorkerGlobalScope.close() does not then allow the SharedWorker to be replaced
https://bugs.webkit.org/show_bug.cgi?id=250839
rdar://problem/104481929

Reviewed by Youenn Fablet.

Shared workers are usually terminated once all their clients go away and the
NetworkProcess is in charge of this.

However, the shared worker can also choose to terminate itself by calling
`self.close()`. In this case, we were failing to notify the network process
that the shared worker had terminated. As a result, when a shared worker
connection request would come in later on, the network process would still
direct it towards the existing (now terminated) shared worker.

To address this issue, we now IPC back from the shared worker process to the
network process when a shared worker gets terminated. This allows the network
process state to remain up-to-date and to make more accurate decisions.

However, doing only this would still be flaky since there can be a race between
the NetworkProcess receiving the IPC about a shared worker being terminated
and a new connection request received by the NetworkProcess. To address this,
I now added a CompletionHandler to the PostConnectEvent IPC from the
NetworkProcess to the SharedWorker process, indicating if we managed to connect
this SharedWorker object to the existing SharedWorker context. In case of
failure, we clean the state in the NetworkProcess and re-attempt the connection,
which will relaunch a SharedWorker.

* LayoutTests/http/wpt/shared-workers/relaunch-after-close-expected.txt: Added.
* LayoutTests/http/wpt/shared-workers/relaunch-after-close.html: Added.
* LayoutTests/http/wpt/shared-workers/resources/relaunch-after-close-page2.html: Added.
* LayoutTests/http/wpt/shared-workers/resources/relaunch-after-close-sharedworker.js: Added.
(shutdown):
(broadcast):
(sendMessageToPortRef):
* LayoutTests/http/wpt/shared-workers/resources/relaunch-after-close-window.js: Added.
(testComplete):
(async beginTestForPage1):
(async beginTestForPage2):
(async initSharedWorker):
(disonnectFromSharedWorker):
(async tellSharedWorkerToShutdown):
(log):
(deferredWithTimeout):
(async wait):
* Source/WebCore/workers/shared/context/SharedWorkerContextManager.cpp:
(WebCore::SharedWorkerContextManager::stopSharedWorker):
* Source/WebCore/workers/shared/context/SharedWorkerContextManager.h:
* Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.cpp:
(WebKit::WebSharedWorkerServer::sharedWorkerTerminated):
* Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.h:
* Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp:
(WebKit::WebSharedWorkerServerToContextConnection::sharedWorkerTerminated):
* Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.h:
* Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.messages.in:
* Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp:
(WebKit::WebSharedWorkerContextManagerConnection::sharedWorkerTerminated):
* Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.h:

Canonical link: https://commits.webkit.org/259228@main




More information about the webkit-changes mailing list