⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 259383 in webkit


Ignore:
Timestamp:
Apr 2, 2020, 4:00:53 AM (6 years ago)
Author:
youenn@apple.com
Message:

Remove synchronous termination of service workers
https://bugs.webkit.org/show_bug.cgi?id=209666

Reviewed by Chris Dumez.

Source/WebCore:

Instead of supporting synchronous IPC to terminate a service worker, SWServerWorker will asynchronously ask for the service worker to terminate.
If it is not terminated after some time, SWServerWorker will then ask to terminate the process running the service worker.
Time is kept to 10 seconds.

We can then remove all synchronous related code related to termination.
We migrate the terminateServiceWorker internal API to be Promise based.

Covered by existing tests.

  • testing/Internals.cpp:

(WebCore::Internals::terminateServiceWorker):

  • testing/Internals.h:
  • testing/Internals.idl:
  • workers/service/ServiceWorkerProvider.h:
  • workers/service/SWClientConnection.h:
  • workers/service/WorkerSWClientConnection.cpp:
  • workers/service/WorkerSWClientConnection.h:
  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::~SWServer):
(WebCore::SWServer::unregisterServiceWorkerClient):

  • workers/service/server/SWServer.h:
  • workers/service/server/SWServerToContextConnection.h:
  • workers/service/server/SWServerWorker.cpp:

(WebCore::m_terminationTimer):
(WebCore::SWServerWorker::~SWServerWorker):
(WebCore::SWServerWorker::terminate):
(WebCore::SWServerWorker::startTermination):
(WebCore::SWServerWorker::terminateCompleted):
(WebCore::SWServerWorker::callTerminationCallbacks):
(WebCore::SWServerWorker::terminationTimerFired):
(WebCore::SWServerWorker::setState):
(WebCore::SWServerWorker::didFailHeartBeatCheck):

  • workers/service/server/SWServerWorker.h:

(WebCore::SWServerWorker::terminate):

Source/WebKit:

Update IPC code according removal of synchronous termination of service worker.
Implement async-with-reply termination instead.

  • NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:

(WebKit::WebSWServerConnection::terminateWorkerFromClient):
(WebKit::WebSWServerConnection::fetchTaskTimedOut):

  • NetworkProcess/ServiceWorker/WebSWServerConnection.h:
  • NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:

(WebKit::WebSWServerToContextConnection::terminateDueToUnresponsiveness):

  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
  • WebProcess/Storage/WebServiceWorkerProvider.cpp:
  • WebProcess/Storage/WebServiceWorkerProvider.h:
  • WebProcess/Storage/WebSWClientConnection.cpp:

(WebKit::WebSWClientConnection::terminateWorkerForTesting):

  • WebProcess/Storage/WebSWClientConnection.h:
  • WebProcess/Storage/WebSWContextManagerConnection.cpp:
  • WebProcess/Storage/WebSWContextManagerConnection.h:
  • WebProcess/Storage/WebSWContextManagerConnection.messages.in:

LayoutTests:

  • http/tests/workers/service/resources/postmessage-after-sw-process-crash.js:

(async event):

  • http/tests/workers/service/resources/postmessage-after-terminate.js:

(async event):

  • http/tests/workers/service/resources/postmessage-after-terminating-hung-worker.js:

(async event):

Location:
trunk
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r259377 r259383  
     12020-04-02  youenn fablet  <youenn@apple.com>
     2
     3        Remove synchronous termination of service workers
     4        https://bugs.webkit.org/show_bug.cgi?id=209666
     5
     6        Reviewed by Chris Dumez.
     7
     8        * http/tests/workers/service/resources/postmessage-after-sw-process-crash.js:
     9        (async event):
     10        * http/tests/workers/service/resources/postmessage-after-terminate.js:
     11        (async event):
     12        * http/tests/workers/service/resources/postmessage-after-terminating-hung-worker.js:
     13        (async event):
     14
    1152020-04-01  Ryan Haddad  <ryanhaddad@apple.com>
    216
  • trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-sw-process-crash.js

    r253103 r259383  
    33let remainingAttempts = 1000; // We try for 10 seconds before timing out.
    44
    5 navigator.serviceWorker.addEventListener("message", function(event) {
     5navigator.serviceWorker.addEventListener("message", async function(event) {
    66    if (!serviceWorkerHasReceivedState) {
    77        if (!event.data) {
     
    1313
    1414        log("* Simulating Service Worker process crash");
    15         testRunner.terminateServiceWorkers();
     15        await testRunner.terminateServiceWorkers();
    1616
    1717        handle = setInterval(function() {
  • trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-terminate.js

    r251067 r259383  
    11var messageNumber = 1;
    2 navigator.serviceWorker.addEventListener("message", function(event) {
     2navigator.serviceWorker.addEventListener("message", async function(event) {
    33    log("PASS: Client received message from service worker, origin: " + event.origin);
    44    log(event.data);
    55    if (messageNumber == 1) {
    6         window.internals.terminateServiceWorker(event.source);
     6        await window.internals.terminateServiceWorker(event.source);
    77        event.source.postMessage("Message 2");
    88        messageNumber++;
  • trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-terminating-hung-worker.js

    r251067 r259383  
    11let state = "WaitingForHang";
    22
    3 navigator.serviceWorker.addEventListener("message", function(event) {
     3navigator.serviceWorker.addEventListener("message", async function(event) {
    44    log(event.data);
    55    if (state === "WaitingForHang") {
     
    77        log("Service Worker should now be hung");
    88        log("Terminating service worker...")
    9         internals.terminateServiceWorker(worker);
     9        await internals.terminateServiceWorker(worker);
    1010        log("Terminated service worker.");
    1111        state = "WaitingForMessageAfterTerminatingHungServiceWorker"
  • trunk/Source/WebCore/ChangeLog

    r259379 r259383  
     12020-04-02  youenn fablet  <youenn@apple.com>
     2
     3        Remove synchronous termination of service workers
     4        https://bugs.webkit.org/show_bug.cgi?id=209666
     5
     6        Reviewed by Chris Dumez.
     7
     8        Instead of supporting synchronous IPC to terminate a service worker, SWServerWorker will asynchronously ask for the service worker to terminate.
     9        If it is not terminated after some time, SWServerWorker will then ask to terminate the process running the service worker.
     10        Time is kept to 10 seconds.
     11
     12        We can then remove all synchronous related code related to termination.
     13        We migrate the terminateServiceWorker internal API to be Promise based.
     14
     15        Covered by existing tests.
     16
     17        * testing/Internals.cpp:
     18        (WebCore::Internals::terminateServiceWorker):
     19        * testing/Internals.h:
     20        * testing/Internals.idl:
     21        * workers/service/ServiceWorkerProvider.h:
     22        * workers/service/SWClientConnection.h:
     23        * workers/service/WorkerSWClientConnection.cpp:
     24        * workers/service/WorkerSWClientConnection.h:
     25        * workers/service/server/SWServer.cpp:
     26        (WebCore::SWServer::~SWServer):
     27        (WebCore::SWServer::unregisterServiceWorkerClient):
     28        * workers/service/server/SWServer.h:
     29        * workers/service/server/SWServerToContextConnection.h:
     30        * workers/service/server/SWServerWorker.cpp:
     31        (WebCore::m_terminationTimer):
     32        (WebCore::SWServerWorker::~SWServerWorker):
     33        (WebCore::SWServerWorker::terminate):
     34        (WebCore::SWServerWorker::startTermination):
     35        (WebCore::SWServerWorker::terminateCompleted):
     36        (WebCore::SWServerWorker::callTerminationCallbacks):
     37        (WebCore::SWServerWorker::terminationTimerFired):
     38        (WebCore::SWServerWorker::setState):
     39        (WebCore::SWServerWorker::didFailHeartBeatCheck):
     40        * workers/service/server/SWServerWorker.h:
     41        (WebCore::SWServerWorker::terminate):
     42
    1432020-04-02  Rob Buis  <rbuis@igalia.com>
    244
  • trunk/Source/WebCore/testing/Internals.cpp

    r259374 r259383  
    51535153}
    51545154
    5155 void Internals::terminateServiceWorker(ServiceWorker& worker)
    5156 {
    5157     if (!contextDocument())
    5158         return;
    5159 
    5160     ServiceWorkerProvider::singleton().serviceWorkerConnection().syncTerminateWorker(worker.identifier());
     5155void Internals::terminateServiceWorker(ServiceWorker& worker, DOMPromiseDeferred<void>&& promise)
     5156{
     5157    ServiceWorkerProvider::singleton().terminateWorkerForTesting(worker.identifier(), [promise = WTFMove(promise)]() mutable {
     5158        promise.resolve();
     5159    });
    51615160}
    51625161
  • trunk/Source/WebCore/testing/Internals.h

    r259374 r259383  
    785785    using HasRegistrationPromise = DOMPromiseDeferred<IDLBoolean>;
    786786    void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
    787     void terminateServiceWorker(ServiceWorker&);
     787    void terminateServiceWorker(ServiceWorker&, DOMPromiseDeferred<void>&&);
    788788    void isServiceWorkerRunning(ServiceWorker&, DOMPromiseDeferred<IDLBoolean>&&);
    789789#endif
  • trunk/Source/WebCore/testing/Internals.idl

    r259374 r259383  
    771771
    772772    [Conditional=SERVICE_WORKER] Promise<boolean> hasServiceWorkerRegistration(DOMString scopeURL);
    773     [Conditional=SERVICE_WORKER] void terminateServiceWorker(ServiceWorker worker);
     773    [Conditional=SERVICE_WORKER] Promise<void> terminateServiceWorker(ServiceWorker worker);
    774774    [Conditional=SERVICE_WORKER] Promise<boolean> isServiceWorkerRunning(ServiceWorker worker);
    775775
  • trunk/Source/WebCore/workers/service/SWClientConnection.h

    r256749 r259383  
    8080    virtual SWServerConnectionIdentifier serverConnectionIdentifier() const = 0;
    8181    virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const = 0;
    82     virtual void syncTerminateWorker(ServiceWorkerIdentifier) = 0;
    8382
    8483    virtual void registerServiceWorkerClient(const SecurityOrigin& topOrigin, const ServiceWorkerClientData&, const Optional<ServiceWorkerRegistrationIdentifier>&, const String& userAgent) = 0;
  • trunk/Source/WebCore/workers/service/ServiceWorkerProvider.h

    r255909 r259383  
    4242
    4343    virtual SWClientConnection& serviceWorkerConnection() = 0;
     44    virtual void terminateWorkerForTesting(ServiceWorkerIdentifier, CompletionHandler<void()>&&) = 0;
    4445
    4546    void setMayHaveRegisteredServiceWorkers() { m_mayHaveRegisteredServiceWorkers = true; }
  • trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp

    r256805 r259383  
    156156}
    157157
    158 void WorkerSWClientConnection::syncTerminateWorker(ServiceWorkerIdentifier identifier)
    159 {
    160     callOnMainThread([identifier]() mutable {
    161         auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection();
    162         connection.syncTerminateWorker(identifier);
    163     });
    164 }
    165 
    166158void WorkerSWClientConnection::registerServiceWorkerClient(const SecurityOrigin& topOrigin, const ServiceWorkerClientData& data, const Optional<ServiceWorkerRegistrationIdentifier>& identifier, const String& userAgent)
    167159{
  • trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h

    r256749 r259383  
    5252    SWServerConnectionIdentifier serverConnectionIdentifier() const final;
    5353    bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const final;
    54     void syncTerminateWorker(ServiceWorkerIdentifier) final;
    5554    void registerServiceWorkerClient(const SecurityOrigin& topOrigin, const ServiceWorkerClientData&, const Optional<ServiceWorkerRegistrationIdentifier>&, const String& userAgent) final;
    5655    void unregisterServiceWorkerClient(DocumentIdentifier) final;
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r256900 r259383  
    5050namespace WebCore {
    5151
    52 static Seconds terminationDelay { 10_s };
    53 
    5452SWServer::Connection::Connection(SWServer& server, Identifier identifier)
    5553    : m_server(server)
     
    8078    }
    8179    for (auto& runningWorker : runningWorkers)
    82         terminateWorker(*runningWorker);
     80        runningWorker->terminate();
    8381
    8482    allServers().remove(this);
     
    306304{
    307305    m_server.removeClientServiceWorkerRegistration(*this, identifier);
    308 }
    309 
    310 void SWServer::Connection::syncTerminateWorker(ServiceWorkerIdentifier identifier)
    311 {
    312     if (auto* worker = m_server.workerByID(identifier))
    313         m_server.syncTerminateWorker(*worker);
    314306}
    315307
     
    734726}
    735727
    736 void SWServer::terminateWorker(SWServerWorker& worker)
    737 {
    738     terminateWorkerInternal(worker, Asynchronous);
    739 }
    740 
    741 void SWServer::syncTerminateWorker(SWServerWorker& worker)
    742 {
    743     terminateWorkerInternal(worker, Synchronous);
    744 }
    745 
    746 void SWServer::terminateWorkerInternal(SWServerWorker& worker, TerminationMode mode)
    747 {
    748     ASSERT(m_runningOrTerminatingWorkers.get(worker.identifier()) == &worker);
    749     ASSERT(worker.isRunning());
    750 
    751     RELEASE_LOG(ServiceWorker, "%p - SWServer::terminateWorkerInternal: Terminating service worker %llu", this, worker.identifier().toUInt64());
    752 
    753     worker.setState(SWServerWorker::State::Terminating);
    754 
    755     auto* contextConnection = worker.contextConnection();
    756     ASSERT(contextConnection);
    757     if (!contextConnection) {
    758         LOG_ERROR("Request to terminate a worker whose context connection does not exist");
    759         workerContextTerminated(worker);
    760         return;
    761     }
    762 
    763     switch (mode) {
    764     case Asynchronous:
    765         contextConnection->terminateWorker(worker.identifier());
    766         break;
    767     case Synchronous:
    768         contextConnection->syncTerminateWorker(worker.identifier());
    769         break;
    770     };
    771 }
    772 
    773728void SWServer::markAllWorkersForRegistrableDomainAsTerminated(const RegistrableDomain& registrableDomain)
    774729{
     
    918873            }
    919874            for (auto* worker : workersToTerminate)
    920                 terminateWorker(*worker);
     875                worker->terminate();
    921876
    922877            if (!m_clientsByRegistrableDomain.contains(clientRegistrableDomain)) {
     
    929884            m_clientIdentifiersPerOrigin.remove(clientOrigin);
    930885        });
    931         iterator->value.terminateServiceWorkersTimer->startOneShot(m_isProcessTerminationDelayEnabled && !MemoryPressureHandler::singleton().isUnderMemoryPressure() ? terminationDelay : 0_s);
     886        iterator->value.terminateServiceWorkersTimer->startOneShot(m_isProcessTerminationDelayEnabled && !MemoryPressureHandler::singleton().isUnderMemoryPressure() ? defaultTerminationDelay : 0_s);
    932887    }
    933888
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r256900 r259383  
    103103        WEBCORE_EXPORT void addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier);
    104104        WEBCORE_EXPORT void removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier);
    105         WEBCORE_EXPORT void syncTerminateWorker(ServiceWorkerIdentifier);
    106105        WEBCORE_EXPORT void whenRegistrationReady(uint64_t registrationReadyRequestIdentifier, const SecurityOriginData& topOrigin, const URL& clientURL);
    107106
     
    153152
    154153    void updateWorker(const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy, WorkerType, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&);
    155     void terminateWorker(SWServerWorker&);
    156     WEBCORE_EXPORT void syncTerminateWorker(SWServerWorker&);
    157154    void fireInstallEvent(SWServerWorker&);
    158155    void fireActivateEvent(SWServerWorker&);
     
    216213    WEBCORE_EXPORT void handleLowMemoryWarning();
    217214
     215    static constexpr Seconds defaultTerminationDelay = 10_s;
     216
    218217private:
    219218    void scriptFetchFinished(const ServiceWorkerFetchResult&);
     
    236235
    237236    void performGetOriginsWithRegistrationsCallbacks();
    238 
    239     enum TerminationMode {
    240         Synchronous,
    241         Asynchronous,
    242     };
    243     void terminateWorkerInternal(SWServerWorker&, TerminationMode);
    244237
    245238    void contextConnectionCreated(SWServerToContextConnection&);
  • trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h

    r256900 r259383  
    5555    virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
    5656    virtual void terminateWorker(ServiceWorkerIdentifier) = 0;
    57     virtual void syncTerminateWorker(ServiceWorkerIdentifier) = 0;
    5857    virtual void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<ServiceWorkerClientData>&, bool hasSecurityError) = 0;
    5958    virtual void matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>&) = 0;
     
    7675
    7776    virtual void connectionIsNoLongerNeeded() = 0;
     77    virtual void terminateDueToUnresponsiveness() = 0;
    7878
    7979protected:
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp

    r257929 r259383  
    2929#if ENABLE(SERVICE_WORKER)
    3030
     31#include "Logging.h"
    3132#include "SWServer.h"
    3233#include "SWServerRegistration.h"
     
    5960    , m_registrableDomain(m_data.scriptURL)
    6061    , m_scriptResourceMap(WTFMove(scriptResourceMap))
     62    , m_terminationTimer(*this, &SWServerWorker::terminationTimerFired)
    6163{
    6264    m_data.scriptURL.removeFragmentIdentifier();
     
    7577    auto taken = allWorkers().take(identifier());
    7678    ASSERT_UNUSED(taken, taken == this);
     79
     80    callTerminationCallbacks();
    7781}
    7882
     
    8488}
    8589
    86 void SWServerWorker::terminate()
    87 {
    88     if (isRunning())
    89         m_server->terminateWorker(*this);
     90void SWServerWorker::terminate(CompletionHandler<void()>&& callback)
     91{
     92    if (!m_server)
     93        return callback();
     94
     95    switch (m_state) {
     96    case State::Running:
     97        startTermination(WTFMove(callback));
     98        return;
     99    case State::Terminating:
     100        m_terminationCallbacks.append(WTFMove(callback));
     101        return;
     102    case State::NotRunning:
     103        return callback();
     104    }
     105}
     106
     107void SWServerWorker::startTermination(CompletionHandler<void()>&& callback)
     108{
     109    auto* contextConnection = this->contextConnection();
     110    ASSERT(contextConnection);
     111    if (!contextConnection) {
     112        RELEASE_LOG_ERROR(ServiceWorker, "Request to terminate a worker %llu whose context connection does not exist", identifier().toUInt64());
     113        setState(State::NotRunning);
     114        callback();
     115        m_server->workerContextTerminated(*this);
     116        return;
     117    }
     118
     119    setState(State::Terminating);
     120
     121    m_terminationCallbacks.append(WTFMove(callback));
     122    m_terminationTimer.startOneShot(SWServer::defaultTerminationDelay);
     123
     124    contextConnection->terminateWorker(identifier());
     125}
     126
     127void SWServerWorker::terminationCompleted()
     128{
     129    m_terminationTimer.stop();
     130    callTerminationCallbacks();
     131}
     132
     133void SWServerWorker::callTerminationCallbacks()
     134{
     135    auto callbacks = WTFMove(m_terminationCallbacks);
     136    for (auto& callback : callbacks)
     137        callback();
     138}
     139
     140void SWServerWorker::terminationTimerFired()
     141{
     142    ASSERT(isTerminating());
     143    contextConnection()->terminateDueToUnresponsiveness();
    90144}
    91145
     
    253307        break;
    254308    case State::NotRunning:
     309        terminationCompleted();
     310
    255311        callWhenActivatedHandler(false);
    256312        // As per https://w3c.github.io/ServiceWorker/#activate, a worker goes to activated even if activating fails.
     
    268324void SWServerWorker::didFailHeartBeatCheck()
    269325{
    270     if (m_server && isRunning())
    271         m_server->terminateWorker(*this);
     326    terminate();
    272327}
    273328
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.h

    r256900 r259383  
    3737#include "ServiceWorkerRegistrationKey.h"
    3838#include "ServiceWorkerTypes.h"
     39#include "Timer.h"
     40#include <wtf/CompletionHandler.h>
    3941#include <wtf/RefCounted.h>
    4042#include <wtf/WeakPtr.h>
     
    6163    WEBCORE_EXPORT ~SWServerWorker();
    6264
    63     void terminate();
     65    WEBCORE_EXPORT void terminate(CompletionHandler<void()>&& = [] { });
    6466
    6567    WEBCORE_EXPORT void whenActivated(CompletionHandler<void(bool)>&&);
     
    127129    void callWhenActivatedHandler(bool success);
    128130
     131    void startTermination(CompletionHandler<void()>&&);
     132    void terminationCompleted();
     133    void terminationTimerFired();
     134    void callTerminationCallbacks();
     135
    129136    WeakPtr<SWServer> m_server;
    130137    ServiceWorkerRegistrationKey m_registrationKey;
     
    143150    bool m_shouldSkipHandleFetch;
    144151    bool m_hasTimedOutAnyFetchTasks { false };
     152    Vector<CompletionHandler<void()>> m_terminationCallbacks;
     153    Timer m_terminationTimer;
    145154};
    146155
  • trunk/Source/WebKit/ChangeLog

    r259382 r259383  
     12020-04-02  youenn fablet  <youenn@apple.com>
     2
     3        Remove synchronous termination of service workers
     4        https://bugs.webkit.org/show_bug.cgi?id=209666
     5
     6        Reviewed by Chris Dumez.
     7
     8        Update IPC code according removal of synchronous termination of service worker.
     9        Implement async-with-reply termination instead.
     10
     11        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
     12        (WebKit::WebSWServerConnection::terminateWorkerFromClient):
     13        (WebKit::WebSWServerConnection::fetchTaskTimedOut):
     14        * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
     15        * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
     16        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
     17        (WebKit::WebSWServerToContextConnection::terminateDueToUnresponsiveness):
     18        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
     19        * WebProcess/Storage/WebServiceWorkerProvider.cpp:
     20        * WebProcess/Storage/WebServiceWorkerProvider.h:
     21        * WebProcess/Storage/WebSWClientConnection.cpp:
     22        (WebKit::WebSWClientConnection::terminateWorkerForTesting):
     23        * WebProcess/Storage/WebSWClientConnection.h:
     24        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
     25        * WebProcess/Storage/WebSWContextManagerConnection.h:
     26        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
     27
    1282020-04-02  Adrian Perez de Castro  <aperez@igalia.com>
    229
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp

    r257413 r259383  
    457457}
    458458
    459 void WebSWServerConnection::syncTerminateWorkerFromClient(ServiceWorkerIdentifier identifier, CompletionHandler<void()>&& completionHandler)
    460 {
    461     syncTerminateWorker(WTFMove(identifier));
    462     completionHandler();
     459void WebSWServerConnection::terminateWorkerFromClient(ServiceWorkerIdentifier serviceWorkerIdentifier, CompletionHandler<void()>&& callback)
     460{
     461    auto* worker = server().workerByID(serviceWorkerIdentifier);
     462    if (!worker)
     463        return callback();
     464    worker->terminate(WTFMove(callback));
    463465}
    464466
     
    486488
    487489    worker->setHasTimedOutAnyFetchTasks();
    488     if (worker->isRunning())
    489         server().syncTerminateWorker(*worker);
     490    worker->terminate();
    490491}
    491492
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h

    r256749 r259383  
    7171
    7272    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
    73     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
    7473   
    7574    PAL::SessionID sessionID() const;
     
    104103    void registerServiceWorkerClient(WebCore::SecurityOriginData&& topOrigin, WebCore::ServiceWorkerClientData&&, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>&, String&& userAgent);
    105104    void unregisterServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier&);
    106     void syncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&);
     105    void terminateWorkerFromClient(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&);
    107106    void isServiceWorkerRunning(WebCore::ServiceWorkerIdentifier, CompletionHandler<void(bool)>&&);
    108107
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in

    r256749 r259383  
    4242    UnregisterServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier identifier)
    4343
    44     SyncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier workerIdentifier) -> () Synchronous
     44    TerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier workerIdentifier) -> () Async
    4545
    4646    SetThrottleState(bool isThrottleable)
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp

    r257365 r259383  
    107107}
    108108
    109 void WebSWServerToContextConnection::syncTerminateWorker(ServiceWorkerIdentifier serviceWorkerIdentifier)
     109void WebSWServerToContextConnection::terminateDueToUnresponsiveness()
    110110{
    111     if (!sendSync(Messages::WebSWContextManagerConnection::SyncTerminateWorker(serviceWorkerIdentifier), Messages::WebSWContextManagerConnection::SyncTerminateWorker::Reply(), 0, 10_s, IPC::SendSyncOption::ForceDispatchWhenDestinationIsWaitingForUnboundedSyncReply))
    112         m_connection.networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::TerminateUnresponsiveServiceWorkerProcesses { webProcessIdentifier() }, 0);
     111    m_connection.networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::TerminateUnresponsiveServiceWorkerProcesses { webProcessIdentifier() }, 0);
    113112}
    114113
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h

    r256900 r259383  
    8888    void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
    8989    void terminateWorker(WebCore::ServiceWorkerIdentifier) final;
    90     void syncTerminateWorker(WebCore::ServiceWorkerIdentifier) final;
    9190    void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<WebCore::ServiceWorkerClientData>&, bool hasSecurityError) final;
    9291    void matchAllCompleted(uint64_t requestIdentifier, const Vector<WebCore::ServiceWorkerClientData>&) final;
    9392
    9493    void connectionIsNoLongerNeeded() final;
     94    void terminateDueToUnresponsiveness() final;
    9595
    9696    void connectionClosed();
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp

    r256805 r259383  
    244244}
    245245
    246 void WebSWClientConnection::syncTerminateWorker(ServiceWorkerIdentifier identifier)
    247 {
    248     sendSync(Messages::WebSWServerConnection::SyncTerminateWorkerFromClient { identifier }, Messages::WebSWServerConnection::SyncTerminateWorkerFromClient::Reply());
     246void WebSWClientConnection::terminateWorkerForTesting(ServiceWorkerIdentifier identifier, CompletionHandler<void()>&& callback)
     247{
     248    sendWithAsyncReply(Messages::WebSWServerConnection::TerminateWorkerFromClient { identifier }, WTFMove(callback));
    249249}
    250250
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h

    r256749 r259383  
    6363    void connectionToServerLost();
    6464
    65     void syncTerminateWorker(WebCore::ServiceWorkerIdentifier) final;
    66 
    6765    bool isThrottleable() const { return m_isThrottleable; }
    6866    void updateThrottleState();
     67
     68    void terminateWorkerForTesting(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&);
    6969
    7070private:
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp

    r258628 r259383  
    256256}
    257257
    258 void WebSWContextManagerConnection::syncTerminateWorker(ServiceWorkerIdentifier identifier, Messages::WebSWContextManagerConnection::SyncTerminateWorker::DelayedReply&& reply)
    259 {
    260     SWContextManager::singleton().terminateWorker(identifier, SWContextManager::syncWorkerTerminationTimeout, WTFMove(reply));
    261 }
    262 
    263258void WebSWContextManagerConnection::postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, const MessageWithMessagePorts& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
    264259{
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h

    r258628 r259383  
    6161
    6262    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
    63     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) final;
    6463
    6564private:
     
    9291    void fireActivateEvent(WebCore::ServiceWorkerIdentifier);
    9392    void terminateWorker(WebCore::ServiceWorkerIdentifier);
    94     void syncTerminateWorker(WebCore::ServiceWorkerIdentifier, Messages::WebSWContextManagerConnection::SyncTerminateWorkerDelayedReply&&);
    9593    void findClientByIdentifierCompleted(uint64_t requestIdentifier, Optional<WebCore::ServiceWorkerClientData>&&, bool hasSecurityError);
    9694    void matchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientData>&&);
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in

    r256900 r259383  
    3232    FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)
    3333    TerminateWorker(WebCore::ServiceWorkerIdentifier identifier)
    34     SyncTerminateWorker(WebCore::ServiceWorkerIdentifier identifier) -> () Synchronous
    3534    FindClientByIdentifierCompleted(uint64_t clientIdRequestIdentifier, Optional<WebCore::ServiceWorkerClientData> data, bool hasSecurityError)
    3635    MatchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientData> clientsData)
  • trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp

    r251470 r259383  
    7171}
    7272
     73void WebServiceWorkerProvider::terminateWorkerForTesting(WebCore::ServiceWorkerIdentifier identifier, CompletionHandler<void()>&& callback)
     74{
     75    WebProcess::singleton().ensureNetworkProcessConnection().serviceWorkerConnection().terminateWorkerForTesting(identifier, WTFMove(callback));
     76}
     77
    7378} // namespace WebKit
    7479
  • trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h

    r252030 r259383  
    5454
    5555    WebCore::SWClientConnection& serviceWorkerConnection() final;
     56    void terminateWorkerForTesting(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&) final;
    5657}; // class WebServiceWorkerProvider
    5758
Note: See TracChangeset for help on using the changeset viewer.