Changeset 278274 in webkit
- Timestamp:
- May 31, 2021, 1:29:02 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 8 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/wpt/service-workers/fetch-worker-terminate-worker.js (added)
-
LayoutTests/http/wpt/service-workers/fetch-worker-terminate.https-expected.txt (added)
-
LayoutTests/http/wpt/service-workers/fetch-worker-terminate.https.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/testing/ServiceWorkerInternals.cpp (modified) (1 diff)
-
Source/WebCore/testing/ServiceWorkerInternals.h (modified) (1 diff)
-
Source/WebCore/testing/ServiceWorkerInternals.idl (modified) (1 diff)
-
Source/WebCore/workers/service/FetchEvent.cpp (modified) (2 diffs)
-
Source/WebCore/workers/service/FetchEvent.h (modified) (2 diffs)
-
Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r278271 r278274 1 2021-05-31 Youenn Fablet <youenn@apple.com> 2 3 Go to network in case fetch event is not yet responded when being destroyed instead of failing the load 4 https://bugs.webkit.org/show_bug.cgi?id=226374 5 <rdar://78298472> 6 7 Reviewed by Alex Christensen. 8 9 * http/wpt/service-workers/fetch-worker-terminate-worker.js: Added. 10 (doTest): 11 * http/wpt/service-workers/fetch-worker-terminate.https-expected.txt: Added. 12 * http/wpt/service-workers/fetch-worker-terminate.https.html: Added. 13 1 14 2021-05-30 Wenson Hsieh <wenson_hsieh@apple.com> 2 15 -
trunk/Source/WebCore/ChangeLog
r278271 r278274 1 2021-05-31 Youenn Fablet <youenn@apple.com> 2 3 Go to network in case fetch event is not yet responded when being destroyed instead of failing the load 4 https://bugs.webkit.org/show_bug.cgi?id=226374 5 <rdar://78298472> 6 7 Reviewed by Alex Christensen. 8 9 In case worker is terminated, instead of failing fetch events that are pending a response, we should go to the network. 10 This mirrors what is already done in ServiceWorkerFetchTask. 11 12 This can for instance happen in case a lot of fetches are done in parallel on the same service worker. 13 The service worker will do the fetch itself but given there are lots of fetches, some fetch might not start until other loads are complete. 14 This may trigger the fetch timeout which might then trigger terminating the worker. 15 We should probably revisit our fetch timeout policy now that we have added worker spin detection. 16 17 Test: http/wpt/service-workers/fetch-worker-terminate.https.html 18 19 * testing/ServiceWorkerInternals.cpp: 20 (WebCore::ServiceWorkerInternals::terminate): 21 (WebCore::ServiceWorkerInternals::waitForFetchEventToFinish): 22 * testing/ServiceWorkerInternals.h: 23 * testing/ServiceWorkerInternals.idl: 24 * workers/service/FetchEvent.cpp: 25 (WebCore::FetchEvent::~FetchEvent): 26 Update logging to only log the case where respondWith is called but fetch event is destroyed before processing the response. 27 Otherwise, we would log the case of respondWith being never called, which is happening often and leads to go to the network. 28 (WebCore::FetchEvent::processResponse): 29 * workers/service/FetchEvent.h: 30 * workers/service/context/ServiceWorkerFetch.cpp: 31 (WebCore::ServiceWorkerFetch::processResponse): 32 1 33 2021-05-30 Wenson Hsieh <wenson_hsieh@apple.com> 2 34 -
trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp
r277837 r278274 51 51 } 52 52 53 void ServiceWorkerInternals::terminate() 54 { 55 callOnMainThread([identifier = m_identifier] () { 56 SWContextManager::singleton().terminateWorker(identifier, Seconds::infinity(), [] { }); 57 }); 58 } 59 53 60 void ServiceWorkerInternals::waitForFetchEventToFinish(FetchEvent& event, DOMPromiseDeferred<IDLInterface<FetchResponse>>&& promise) 54 61 { 55 62 event.onResponse([promise = WTFMove(promise), event = makeRef(event)] (auto&& result) mutable { 56 if (result.has_value()) 57 promise.resolve(WTFMove(result.value())); 58 else 59 promise.reject(TypeError, result.error().localizedDescription()); 63 if (!result.has_value()) { 64 String description; 65 if (auto& error = result.error()) 66 description = error->localizedDescription(); 67 promise.reject(TypeError, description); 68 return; 69 } 70 promise.resolve(WTFMove(result.value())); 60 71 }); 61 72 } -
trunk/Source/WebCore/testing/ServiceWorkerInternals.h
r277837 r278274 47 47 48 48 void setOnline(bool isOnline); 49 void terminate(); 50 49 51 void waitForFetchEventToFinish(FetchEvent&, DOMPromiseDeferred<IDLInterface<FetchResponse>>&&); 50 52 Ref<FetchEvent> createBeingDispatchedFetchEvent(ScriptExecutionContext&); -
trunk/Source/WebCore/testing/ServiceWorkerInternals.idl
r277837 r278274 31 31 ] interface ServiceWorkerInternals { 32 32 undefined setOnline(boolean isOnline); 33 undefined terminate(); 34 33 35 Promise<FetchResponse> waitForFetchEventToFinish(FetchEvent event); 34 36 [CallWith=ScriptExecutionContext] FetchEvent createBeingDispatchedFetchEvent(); -
trunk/Source/WebCore/workers/service/FetchEvent.cpp
r277864 r278274 57 57 { 58 58 if (auto callback = WTFMove(m_onResponse)) { 59 RELEASE_LOG_ERROR (ServiceWorker, "Fetch event is destroyed without a response, respondWithEntered=%d, waitToRespond=%d, respondWithError=%d, respondPromise=%d", m_respondWithEntered, m_waitToRespond, m_respondWithError, !!m_respondPromise);60 callback(makeUnexpected( ResourceError { errorDomainWebKitServiceWorker, 0, m_request->url(), "Fetch event is destroyed."_s, ResourceError::Type::Cancellation}));59 RELEASE_LOG_ERROR_IF(m_respondWithEntered, ServiceWorker, "Fetch event is destroyed without a response, respondWithEntered=%d, waitToRespond=%d, respondWithError=%d, respondPromise=%d", m_respondWithEntered, m_waitToRespond, m_respondWithError, !!m_respondPromise); 60 callback(makeUnexpected(std::optional<ResourceError> { })); 61 61 } 62 62 } … … 107 107 } 108 108 109 void FetchEvent::processResponse(Expected<Ref<FetchResponse>, ResourceError>&& result)109 void FetchEvent::processResponse(Expected<Ref<FetchResponse>, std::optional<ResourceError>>&& result) 110 110 { 111 111 m_respondPromise = nullptr; -
trunk/Source/WebCore/workers/service/FetchEvent.h
r250060 r278274 60 60 ExceptionOr<void> respondWith(Ref<DOMPromise>&&); 61 61 62 using ResponseCallback = CompletionHandler<void(Expected<Ref<FetchResponse>, ResourceError>&&)>;62 using ResponseCallback = CompletionHandler<void(Expected<Ref<FetchResponse>, std::optional<ResourceError>>&&)>; 63 63 WEBCORE_EXPORT void onResponse(ResponseCallback&&); 64 64 … … 76 76 77 77 void promiseIsSettled(); 78 void processResponse(Expected<Ref<FetchResponse>, ResourceError>&&);78 void processResponse(Expected<Ref<FetchResponse>, std::optional<ResourceError>>&&); 79 79 void respondWithError(ResourceError&&); 80 80 -
trunk/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp
r278253 r278274 66 66 } 67 67 68 static void processResponse(Ref<Client>&& client, Expected<Ref<FetchResponse>, ResourceError>&& result, FetchOptions::Mode mode, FetchOptions::Redirect redirect, const URL& requestURL, CertificateInfo&& certificateInfo)68 static void processResponse(Ref<Client>&& client, Expected<Ref<FetchResponse>, std::optional<ResourceError>>&& result, FetchOptions::Mode mode, FetchOptions::Redirect redirect, const URL& requestURL, CertificateInfo&& certificateInfo) 69 69 { 70 70 if (!result.has_value()) { 71 client->didFail(result.error()); 71 auto& error = result.error(); 72 if (!error) { 73 client->didNotHandle(); 74 return; 75 } 76 client->didFail(*error); 72 77 return; 73 78 }
Note:
See TracChangeset
for help on using the changeset viewer.