- Revision
- 289338
- Author
- [email protected]
- Date
- 2022-02-07 18:57:24 -0800 (Mon, 07 Feb 2022)
Log Message
Cherry-pick r288949. rdar://problem/88226432
ServiceWorkerNavigationPreloader should only be used once
https://bugs.webkit.org/show_bug.cgi?id=235882
<rdar://88226432>
Reviewed by Chris Dumez.
Source/WebKit:
In case service worker preload is being used and related service worker context crashes (or service worker context sends bad messages),
We can end up in a bad state where we will ask the preload twice for the same response (once for good, and the next one as we go to didNotHandle case).
To prevent this, we add checks in loadResponseFromPreloader and loadBodyFromPreloader.
As part of this investigation, I found out that ServiceWorkerNavigationPreloader is not correctly handling the case of preload responses coming from cache.
In particular, no body will be given since we return early in waitForBody in case the preload network load is null.
Prevent this by making sure waitForBody calls the response completion handler if available, even if the preload network load is null.
And update the response body callback before executing the response completion handler to make sure data received synchronously from the preload is given to the service worker fetch task.
Test: http/wpt/service-workers/fetch-service-worker-preload-cache.https.html
* NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
* NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp:
LayoutTests:
* http/wpt/service-workers/fetch-service-worker-preload-cache.https-expected.txt: Added.
* http/wpt/service-workers/fetch-service-worker-preload-cache.https.html: Added.
* http/wpt/service-workers/resources/fetch-service-worker-preload-script.py:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288949 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Added Paths
Diff
Modified: branches/safari-613-branch/LayoutTests/ChangeLog (289337 => 289338)
--- branches/safari-613-branch/LayoutTests/ChangeLog 2022-02-08 02:57:20 UTC (rev 289337)
+++ branches/safari-613-branch/LayoutTests/ChangeLog 2022-02-08 02:57:24 UTC (rev 289338)
@@ -1,5 +1,51 @@
2022-02-07 Russell Epstein <[email protected]>
+ Cherry-pick r288949. rdar://problem/88226432
+
+ ServiceWorkerNavigationPreloader should only be used once
+ https://bugs.webkit.org/show_bug.cgi?id=235882
+ <rdar://88226432>
+
+ Reviewed by Chris Dumez.
+
+ Source/WebKit:
+
+ In case service worker preload is being used and related service worker context crashes (or service worker context sends bad messages),
+ We can end up in a bad state where we will ask the preload twice for the same response (once for good, and the next one as we go to didNotHandle case).
+ To prevent this, we add checks in loadResponseFromPreloader and loadBodyFromPreloader.
+ As part of this investigation, I found out that ServiceWorkerNavigationPreloader is not correctly handling the case of preload responses coming from cache.
+ In particular, no body will be given since we return early in waitForBody in case the preload network load is null.
+ Prevent this by making sure waitForBody calls the response completion handler if available, even if the preload network load is null.
+ And update the response body callback before executing the response completion handler to make sure data received synchronously from the preload is given to the service worker fetch task.
+
+ Test: http/wpt/service-workers/fetch-service-worker-preload-cache.https.html
+
+ * NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
+ * NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp:
+
+ LayoutTests:
+
+ * http/wpt/service-workers/fetch-service-worker-preload-cache.https-expected.txt: Added.
+ * http/wpt/service-workers/fetch-service-worker-preload-cache.https.html: Added.
+ * http/wpt/service-workers/resources/fetch-service-worker-preload-script.py:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288949 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2022-02-02 Youenn Fablet <[email protected]>
+
+ ServiceWorkerNavigationPreloader should only be used once
+ https://bugs.webkit.org/show_bug.cgi?id=235882
+ <rdar://88226432>
+
+ Reviewed by Chris Dumez.
+
+ * http/wpt/service-workers/fetch-service-worker-preload-cache.https-expected.txt: Added.
+ * http/wpt/service-workers/fetch-service-worker-preload-cache.https.html: Added.
+ * http/wpt/service-workers/resources/fetch-service-worker-preload-script.py:
+
+2022-02-07 Russell Epstein <[email protected]>
+
Cherry-pick r288881. rdar://problem/80246192
Animation from scale(0) has missing backing store
Added: branches/safari-613-branch/LayoutTests/http/wpt/service-workers/fetch-service-worker-preload-cache.https-expected.txt (0 => 289338)
--- branches/safari-613-branch/LayoutTests/http/wpt/service-workers/fetch-service-worker-preload-cache.https-expected.txt (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/wpt/service-workers/fetch-service-worker-preload-cache.https-expected.txt 2022-02-08 02:57:24 UTC (rev 289338)
@@ -0,0 +1,5 @@
+
+
+PASS Setup activating worker
+PASS Service worker load uses preload through calling fetch on the fetch event request
+
Added: branches/safari-613-branch/LayoutTests/http/wpt/service-workers/fetch-service-worker-preload-cache.https.html (0 => 289338)
--- branches/safari-613-branch/LayoutTests/http/wpt/service-workers/fetch-service-worker-preload-cache.https.html (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/wpt/service-workers/fetch-service-worker-preload-cache.https.html 2022-02-08 02:57:24 UTC (rev 289338)
@@ -0,0 +1,70 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var activeWorker;
+var uuid = token();
+var url = "" + uuid;
+var frame;
+const channel = new MessageChannel();
+
+function waitUntilActivating()
+{
+ return new Promise(resolve => {
+ channel.port2._onmessage_ = (event) => {
+ if (event.data ="" "activating")
+ resolve();
+ };
+ });
+}
+
+function triggerActivation()
+{
+ activeWorker.postMessage("activate");
+}
+
+promise_test(async (test) => {
+ if (window.testRunner) {
+ testRunner.setUseSeparateServiceWorkerProcess(true);
+ await fetch("").then(() => { }, () => { });
+ }
+
+ let registration = await navigator.serviceWorker.register("/WebKit/service-workers/fetch-service-worker-preload-worker.js", { scope : url });
+ if (!registration.installing) {
+ registration.unregister();
+ registration = await navigator.serviceWorker.register("/WebKit/service-workers/fetch-service-worker-preload-worker.js", { scope : url });
+ }
+
+ activeWorker = registration.installing;
+ activeWorker.postMessage({ port: channel.port1 }, [channel.port1]);
+
+ return waitUntilActivating();
+}, "Setup activating worker");
+
+promise_test(async (test) => {
+ fetch(url + "&value=use-preload", { method: 'POST' });
+
+ // Put in the cache.
+ await fetch(url);
+
+ // Load iframe, with activating worker, so only preload will start.
+ const promise = withIframe(url);
+
+ triggerActivation();
+
+ const frame = await promise;
+ assert_equals(frame.contentWindow.value, "use-preload");
+
+ // We should have only one GET fetch to url: the service worker preload
+ const response = await fetch(url + "&count=True");
+ assert_equals(await response.text(), "1");
+}, "Service worker load uses preload through calling fetch on the fetch event request");
+</script>
+</body>
+</html>
Modified: branches/safari-613-branch/LayoutTests/http/wpt/service-workers/resources/fetch-service-worker-preload-script.py (289337 => 289338)
--- branches/safari-613-branch/LayoutTests/http/wpt/service-workers/resources/fetch-service-worker-preload-script.py 2022-02-08 02:57:20 UTC (rev 289337)
+++ branches/safari-613-branch/LayoutTests/http/wpt/service-workers/resources/fetch-service-worker-preload-script.py 2022-02-08 02:57:24 UTC (rev 289338)
@@ -30,8 +30,12 @@
value = request.server.stash.take(testId)
if not value:
value = b"nothing"
- response.headers.set(b"Cache-Control", b"no-cache")
+ if b"cache" in request.GET:
+ response.headers.set(b"Cache-Control", b"max-age=31536000")
+ else:
+ response.headers.set(b"Cache-Control", b"no-cache")
+
if b"download" in request.GET:
response.headers.set(b"Content-Type", b"text/vcard")
return value.decode()
Modified: branches/safari-613-branch/Source/WebKit/ChangeLog (289337 => 289338)
--- branches/safari-613-branch/Source/WebKit/ChangeLog 2022-02-08 02:57:20 UTC (rev 289337)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog 2022-02-08 02:57:24 UTC (rev 289338)
@@ -1,5 +1,60 @@
2022-02-07 Russell Epstein <[email protected]>
+ Cherry-pick r288949. rdar://problem/88226432
+
+ ServiceWorkerNavigationPreloader should only be used once
+ https://bugs.webkit.org/show_bug.cgi?id=235882
+ <rdar://88226432>
+
+ Reviewed by Chris Dumez.
+
+ Source/WebKit:
+
+ In case service worker preload is being used and related service worker context crashes (or service worker context sends bad messages),
+ We can end up in a bad state where we will ask the preload twice for the same response (once for good, and the next one as we go to didNotHandle case).
+ To prevent this, we add checks in loadResponseFromPreloader and loadBodyFromPreloader.
+ As part of this investigation, I found out that ServiceWorkerNavigationPreloader is not correctly handling the case of preload responses coming from cache.
+ In particular, no body will be given since we return early in waitForBody in case the preload network load is null.
+ Prevent this by making sure waitForBody calls the response completion handler if available, even if the preload network load is null.
+ And update the response body callback before executing the response completion handler to make sure data received synchronously from the preload is given to the service worker fetch task.
+
+ Test: http/wpt/service-workers/fetch-service-worker-preload-cache.https.html
+
+ * NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
+ * NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp:
+
+ LayoutTests:
+
+ * http/wpt/service-workers/fetch-service-worker-preload-cache.https-expected.txt: Added.
+ * http/wpt/service-workers/fetch-service-worker-preload-cache.https.html: Added.
+ * http/wpt/service-workers/resources/fetch-service-worker-preload-script.py:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288949 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2022-02-02 Youenn Fablet <[email protected]>
+
+ ServiceWorkerNavigationPreloader should only be used once
+ https://bugs.webkit.org/show_bug.cgi?id=235882
+ <rdar://88226432>
+
+ Reviewed by Chris Dumez.
+
+ In case service worker preload is being used and related service worker context crashes (or service worker context sends bad messages),
+ We can end up in a bad state where we will ask the preload twice for the same response (once for good, and the next one as we go to didNotHandle case).
+ To prevent this, we add checks in loadResponseFromPreloader and loadBodyFromPreloader.
+ As part of this investigation, I found out that ServiceWorkerNavigationPreloader is not correctly handling the case of preload responses coming from cache.
+ In particular, no body will be given since we return early in waitForBody in case the preload network load is null.
+ Prevent this by making sure waitForBody calls the response completion handler if available, even if the preload network load is null.
+ And update the response body callback before executing the response completion handler to make sure data received synchronously from the preload is given to the service worker fetch task.
+
+ Test: http/wpt/service-workers/fetch-service-worker-preload-cache.https.html
+
+ * NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
+ * NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp:
+
+2022-02-07 Russell Epstein <[email protected]>
+
Cherry-pick r288924. rdar://problem/87163253
Write origin file when OriginStorageManager is destroyed
Modified: branches/safari-613-branch/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp (289337 => 289338)
--- branches/safari-613-branch/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp 2022-02-08 02:57:20 UTC (rev 289337)
+++ branches/safari-613-branch/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp 2022-02-08 02:57:24 UTC (rev 289338)
@@ -363,7 +363,9 @@
{
SWFETCH_RELEASE_LOG("loadResponseFromPreloader");
- ASSERT(!m_isLoadingFromPreloader);
+ if (m_isLoadingFromPreloader)
+ return;
+
m_isLoadingFromPreloader = true;
m_preloader->waitForResponse([weakThis = WeakPtr { *this }, this] {
@@ -392,6 +394,12 @@
SWFETCH_RELEASE_LOG("loadBodyFromPreloader");
ASSERT(m_isLoadingFromPreloader);
+ if (!m_preloader) {
+ SWFETCH_RELEASE_LOG_ERROR("loadBodyFromPreloader preloader is null");
+ didFail(ResourceError(errorDomainWebKitInternal, 0, m_loader.originalRequest().url(), "Request canceled from preloader"_s, ResourceError::Type::Cancellation));
+ return;
+ }
+
m_preloader->waitForBody([weakThis = WeakPtr { *this }, this](auto&& chunk, int length) {
if (!weakThis)
return;
Modified: branches/safari-613-branch/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp (289337 => 289338)
--- branches/safari-613-branch/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp 2022-02-08 02:57:20 UTC (rev 289337)
+++ branches/safari-613-branch/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp 2022-02-08 02:57:24 UTC (rev 289338)
@@ -231,20 +231,14 @@
void ServiceWorkerNavigationPreloader::waitForBody(BodyCallback&& callback)
{
- if (!m_error.isNull()) {
+ if (!m_error.isNull() || !m_responseCompletionHandler) {
callback({ }, 0);
return;
}
ASSERT(!m_response.isNull());
- ASSERT(m_responseCompletionHandler || !m_networkLoad);
- if (!m_networkLoad) {
- callback({ }, 0);
- return;
- }
- if (m_responseCompletionHandler)
- m_responseCompletionHandler(PolicyAction::Use);
m_bodyCallback = WTFMove(callback);
+ m_responseCompletionHandler(PolicyAction::Use);
}
bool ServiceWorkerNavigationPreloader::convertToDownload(DownloadManager& manager, DownloadID downloadID, const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response)