Changeset 259859 in webkit
- Timestamp:
- Apr 10, 2020, 3:50:35 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/wpt/service-workers/resources/routines.js (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/testing/Internals.cpp (modified) (1 diff)
-
Source/WebCore/testing/Internals.h (modified) (1 diff)
-
Source/WebCore/testing/Internals.idl (modified) (1 diff)
-
Source/WebCore/workers/service/SWClientConnection.h (modified) (1 diff)
-
Source/WebCore/workers/service/server/SWServer.cpp (modified) (3 diffs)
-
Source/WebCore/workers/service/server/SWServerWorker.cpp (modified) (2 diffs)
-
Source/WebCore/workers/service/server/SWServerWorker.h (modified) (2 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in (modified) (1 diff)
-
Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (modified) (1 diff)
-
Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r259850 r259859 1 2020-04-10 Youenn Fablet <youenn@apple.com> 2 3 SWServer should not run a service worker that is terminating 4 https://bugs.webkit.org/show_bug.cgi?id=210044 5 6 Reviewed by Chris Dumez. 7 8 * http/wpt/service-workers/resources/routines.js: 9 (async waitForServiceWorkerNoLongerRunning): 10 Use new internals API. 11 1 12 2020-04-09 Peng Liu <peng.liu6@apple.com> 2 13 -
trunk/LayoutTests/http/wpt/service-workers/resources/routines.js
r253898 r259859 34 34 return Promise.reject("requires internals"); 35 35 36 let count = 100; 37 while (--count > 0 && await internals.isServiceWorkerRunning(worker)) { 38 worker.postMessage("test"); 39 await new Promise(resolve => setTimeout(resolve, 50)); 40 } 41 if (count === 0) 42 return Promise.reject("service worker is still running"); 36 const promise = internals.whenServiceWorkerIsTerminated(worker); 37 let timer = setInterval(() => worker.postMessage("test"), 50); 38 await promise; 39 clearInterval(timer); 43 40 } -
trunk/Source/WebCore/ChangeLog
r259858 r259859 1 2020-04-10 Youenn Fablet <youenn@apple.com> 2 3 SWServer should not run a service worker that is terminating 4 https://bugs.webkit.org/show_bug.cgi?id=210044 5 6 Reviewed by Chris Dumez. 7 8 If a test is being terminated and we want to restart it, we were previously running it right away. 9 This does not work well as the service worker process might still have the terminating service worker in its map. 10 Also, if the service worker is not able to terminate properly, we will kill the service worker process so there is no reason 11 to try running this service worker in this process. 12 Instead, wait for the service worker to terminate (which might include terminating the service worker process). 13 14 In addition, we remove the isServiceWorkerRunning internals API since this is potentially flaky as the service worker 15 might be terminated and rerunning in between two isServiceWorkerRunning checks. 16 Instead, we introduce whenServiceWorkerIsTerminated which will resolve as soon as the service worker goes to terminated. 17 18 Covered by existing spinning tests no longer crashing. 19 20 * testing/Internals.cpp: 21 (WebCore::Internals::whenServiceWorkerIsTerminated): 22 * testing/Internals.h: 23 * testing/Internals.idl: 24 * workers/service/SWClientConnection.h: 25 (WebCore::SWClientConnection::whenServiceWorkerIsTerminatedForTesting): 26 * workers/service/server/SWServer.cpp: 27 (WebCore::SWServer::runServiceWorkerIfNecessary): 28 (WebCore::SWServer::runServiceWorker): 29 (WebCore::SWServer::workerContextTerminated): 30 * workers/service/server/SWServerWorker.cpp: 31 (WebCore::SWServerWorker::whenTerminated): 32 (WebCore::SWServerWorker::setState): 33 * workers/service/server/SWServerWorker.h: 34 (WebCore::SWServerWorker::isNotRunning const): 35 1 36 2020-04-10 Charlie Turner <cturner@igalia.com> 2 37 -
trunk/Source/WebCore/testing/Internals.cpp
r259824 r259859 5145 5145 } 5146 5146 5147 void Internals:: isServiceWorkerRunning(ServiceWorker& worker, DOMPromiseDeferred<IDLBoolean>&& promise)5148 { 5149 return ServiceWorkerProvider::singleton().serviceWorkerConnection(). isServiceWorkerRunning(worker.identifier(), [promise = WTFMove(promise)](bool result) mutable {5150 promise.resolve( result);5147 void Internals::whenServiceWorkerIsTerminated(ServiceWorker& worker, DOMPromiseDeferred<void>&& promise) 5148 { 5149 return ServiceWorkerProvider::singleton().serviceWorkerConnection().whenServiceWorkerIsTerminatedForTesting(worker.identifier(), [promise = WTFMove(promise)]() mutable { 5150 promise.resolve(); 5151 5151 }); 5152 5152 } -
trunk/Source/WebCore/testing/Internals.h
r259824 r259859 785 785 void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&); 786 786 void terminateServiceWorker(ServiceWorker&, DOMPromiseDeferred<void>&&); 787 void isServiceWorkerRunning(ServiceWorker&, DOMPromiseDeferred<IDLBoolean>&&);787 void whenServiceWorkerIsTerminated(ServiceWorker&, DOMPromiseDeferred<void>&&); 788 788 #endif 789 789 -
trunk/Source/WebCore/testing/Internals.idl
r259575 r259859 771 771 [Conditional=SERVICE_WORKER] Promise<boolean> hasServiceWorkerRegistration(DOMString scopeURL); 772 772 [Conditional=SERVICE_WORKER] Promise<void> terminateServiceWorker(ServiceWorker worker); 773 [Conditional=SERVICE_WORKER] Promise< boolean> isServiceWorkerRunning(ServiceWorker worker);773 [Conditional=SERVICE_WORKER] Promise<void> whenServiceWorkerIsTerminated(ServiceWorker worker); 774 774 775 775 [CallWith=Document, Conditional=APPLE_PAY] readonly attribute MockPaymentCoordinator mockPaymentCoordinator; -
trunk/Source/WebCore/workers/service/SWClientConnection.h
r259383 r259859 87 87 88 88 virtual void storeRegistrationsOnDiskForTesting(CompletionHandler<void()>&& callback) { callback(); } 89 virtual void isServiceWorkerRunning(ServiceWorkerIdentifier, CompletionHandler<void(bool)>&& callback) { callback(false); }89 virtual void whenServiceWorkerIsTerminatedForTesting(ServiceWorkerIdentifier, CompletionHandler<void()>&& callback) { callback(); } 90 90 91 91 WEBCORE_EXPORT void registerServiceWorkerClients(); -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r259383 r259859 686 686 } 687 687 688 if (worker->isTerminating()) { 689 worker->whenTerminated([this, weakThis = makeWeakPtr(this), identifier, callback = WTFMove(callback)]() mutable { 690 if (!weakThis) 691 return callback(nullptr); 692 runServiceWorkerIfNecessary(identifier, WTFMove(callback)); 693 }); 694 return; 695 } 696 688 697 if (!contextConnection) { 689 698 auto& serviceWorkerRunRequestsForOrigin = m_serviceWorkerRunRequests.ensure(worker->registrableDomain(), [] { … … 713 722 return false; 714 723 715 auto addResult = m_runningOrTerminatingWorkers.add(identifier, *worker); 716 ASSERT_UNUSED(addResult, addResult.isNewEntry || worker->isTerminating()); 724 ASSERT(!worker->isTerminating()); 725 ASSERT(!m_runningOrTerminatingWorkers.contains(identifier)); 726 m_runningOrTerminatingWorkers.add(identifier, *worker); 717 727 718 728 worker->setState(SWServerWorker::State::Running); … … 739 749 void SWServer::workerContextTerminated(SWServerWorker& worker) 740 750 { 741 worker.setState(SWServerWorker::State::NotRunning);742 743 if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))744 jobQueue->cancelJobsFromServiceWorker(worker.identifier());745 746 751 // At this point if no registrations are referencing the worker then it will be destroyed, 747 752 // removing itself from the m_workersByID map. 748 753 auto result = m_runningOrTerminatingWorkers.take(worker.identifier()); 749 754 ASSERT_UNUSED(result, result && result->ptr() == &worker); 755 756 worker.setState(SWServerWorker::State::NotRunning); 757 758 if (auto* jobQueue = m_jobQueues.get(worker.registrationKey())) 759 jobQueue->cancelJobsFromServiceWorker(worker.identifier()); 750 760 } 751 761 -
trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp
r259383 r259859 105 105 } 106 106 107 void SWServerWorker::whenTerminated(CompletionHandler<void()>&& callback) 108 { 109 ASSERT(isRunning() || isTerminating()); 110 m_terminationCallbacks.append(WTFMove(callback)); 111 } 112 107 113 void SWServerWorker::startTermination(CompletionHandler<void()>&& callback) 108 114 { … … 297 303 { 298 304 ASSERT(state != State::Running || m_registration); 305 ASSERT(state != State::Running || m_state != State::Terminating); 299 306 m_state = state; 300 307 -
trunk/Source/WebCore/workers/service/server/SWServerWorker.h
r259383 r259859 64 64 65 65 WEBCORE_EXPORT void terminate(CompletionHandler<void()>&& = [] { }); 66 WEBCORE_EXPORT void whenTerminated(CompletionHandler<void()>&&); 66 67 67 68 WEBCORE_EXPORT void whenActivated(CompletionHandler<void(bool)>&&); … … 74 75 bool isRunning() const { return m_state == State::Running; } 75 76 bool isTerminating() const { return m_state == State::Terminating; } 77 bool isNotRunning() const { return m_state == State::NotRunning; } 76 78 void setState(State); 77 79 -
trunk/Source/WebKit/ChangeLog
r259857 r259859 1 2020-04-10 Youenn Fablet <youenn@apple.com> 2 3 SWServer should not run a service worker that is terminating 4 https://bugs.webkit.org/show_bug.cgi?id=210044 5 6 Reviewed by Chris Dumez. 7 8 Implement whenServiceWorkerIsTerminated check. 9 10 * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp: 11 (WebKit::WebSWServerConnection::whenServiceWorkerIsTerminatedForTesting): 12 * NetworkProcess/ServiceWorker/WebSWServerConnection.h: 13 * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in: 14 * WebProcess/Storage/WebSWClientConnection.cpp: 15 (WebKit::WebSWClientConnection::whenServiceWorkerIsTerminatedForTesting): 16 * WebProcess/Storage/WebSWClientConnection.h: 17 1 18 2020-04-10 Commit Queue <commit-queue@webkit.org> 2 19 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp
r259383 r259859 465 465 } 466 466 467 void WebSWServerConnection:: isServiceWorkerRunning(ServiceWorkerIdentifier identifier, CompletionHandler<void(bool)>&& completionHandler)467 void WebSWServerConnection::whenServiceWorkerIsTerminatedForTesting(WebCore::ServiceWorkerIdentifier identifier, CompletionHandler<void()>&& completionHandler) 468 468 { 469 469 auto* worker = SWServerWorker::existingWorkerForIdentifier(identifier); 470 completionHandler(worker ? worker->isRunning() : false); 470 if (!worker || worker->isNotRunning()) 471 return completionHandler(); 472 worker->whenTerminated(WTFMove(completionHandler)); 471 473 } 472 474 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h
r259383 r259859 104 104 void unregisterServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier&); 105 105 void terminateWorkerFromClient(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&); 106 void isServiceWorkerRunning(WebCore::ServiceWorkerIdentifier, CompletionHandler<void(bool)>&&);106 void whenServiceWorkerIsTerminatedForTesting(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&); 107 107 108 108 void postMessageToServiceWorkerClient(WebCore::DocumentIdentifier destinationContextIdentifier, const WebCore::MessageWithMessagePorts&, WebCore::ServiceWorkerIdentifier sourceServiceWorkerIdentifier, const String& sourceOrigin) final; -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in
r259383 r259859 43 43 44 44 TerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier workerIdentifier) -> () Async 45 WhenServiceWorkerIsTerminatedForTesting(WebCore::ServiceWorkerIdentifier workerIdentifier) -> () Async 45 46 46 47 SetThrottleState(bool isThrottleable) 47 48 StoreRegistrationsOnDisk() -> () Async 48 IsServiceWorkerRunning(WebCore::ServiceWorkerIdentifier workerIdentifier) -> (bool isRunning) Async49 49 } 50 50 -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
r259383 r259859 249 249 } 250 250 251 void WebSWClientConnection:: isServiceWorkerRunning(ServiceWorkerIdentifier identifier, CompletionHandler<void(bool)>&& callback)252 { 253 sendWithAsyncReply(Messages::WebSWServerConnection:: IsServiceWorkerRunning { identifier }, WTFMove(callback));251 void WebSWClientConnection::whenServiceWorkerIsTerminatedForTesting(ServiceWorkerIdentifier identifier, CompletionHandler<void()>&& callback) 252 { 253 sendWithAsyncReply(Messages::WebSWServerConnection::WhenServiceWorkerIsTerminatedForTesting { identifier }, WTFMove(callback)); 254 254 } 255 255 -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h
r259383 r259859 87 87 88 88 void getRegistrations(WebCore::SecurityOriginData&& topOrigin, const URL& clientURL, GetRegistrationsCallback&&) final; 89 void isServiceWorkerRunning(WebCore::ServiceWorkerIdentifier, CompletionHandler<void(bool)>&&) final;89 void whenServiceWorkerIsTerminatedForTesting(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&) final; 90 90 91 91 void didResolveRegistrationPromise(const WebCore::ServiceWorkerRegistrationKey&) final;
Note:
See TracChangeset
for help on using the changeset viewer.