LinkLoader fails to remove CachedResourceClient in some cases
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2018 19:05:36 +0000 (19:05 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2018 19:05:36 +0000 (19:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185553
<rdar://problem/36879656>

Reviewed by Geoffrey Garen.

Source/WebCore:

Test: http/tests/preload/link-preload-client-remove.html

* loader/LinkLoader.cpp:
(WebCore::LinkLoader::loadLink):

If there is a link preload already in progress, we fail to clear the client for the ongoing load.
This may leave the CachedResource client map in a bad state.

LayoutTests:

* http/tests/preload/link-preload-client-remove-expected.txt: Added.
* http/tests/preload/link-preload-client-remove.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231713 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/preload/link-preload-client-remove-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/preload/link-preload-client-remove.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/loader/LinkLoader.cpp

index 5223243..2a97810 100644 (file)
@@ -1,3 +1,14 @@
+2018-05-11  Antti Koivisto  <antti@apple.com>
+
+        LinkLoader fails to remove CachedResourceClient in some cases
+        https://bugs.webkit.org/show_bug.cgi?id=185553
+        <rdar://problem/36879656>
+
+        Reviewed by Geoffrey Garen.
+
+        * http/tests/preload/link-preload-client-remove-expected.txt: Added.
+        * http/tests/preload/link-preload-client-remove.html: Added.
+
 2018-05-11  Charles Vazac  <cvazac@gmail.com>
 
         Runtime feature flag for Server-Timing
diff --git a/LayoutTests/http/tests/preload/link-preload-client-remove-expected.txt b/LayoutTests/http/tests/preload/link-preload-client-remove-expected.txt
new file mode 100644 (file)
index 0000000..1c2c364
--- /dev/null
@@ -0,0 +1 @@
+Test that restarting link preload doesn't assert or crash.
diff --git a/LayoutTests/http/tests/preload/link-preload-client-remove.html b/LayoutTests/http/tests/preload/link-preload-client-remove.html
new file mode 100644 (file)
index 0000000..ee9208d
--- /dev/null
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText()
+    testRunner.waitUntilDone();
+    window.addEventListener("load", function() {
+        testRunner.notifyDone();
+    });
+}
+</script>
+<link id=link rel=preload href="../resources/dummy.js" as=fetch>
+<body>
+Test that restarting link preload doesn't assert or crash.
+</body>
+<script>
+link.setAttribute("rel", "preload");
+</script>
index 76a3898..b6bc4a4 100644 (file)
@@ -1,3 +1,19 @@
+2018-05-11  Antti Koivisto  <antti@apple.com>
+
+        LinkLoader fails to remove CachedResourceClient in some cases
+        https://bugs.webkit.org/show_bug.cgi?id=185553
+        <rdar://problem/36879656>
+
+        Reviewed by Geoffrey Garen.
+
+        Test: http/tests/preload/link-preload-client-remove.html
+
+        * loader/LinkLoader.cpp:
+        (WebCore::LinkLoader::loadLink):
+
+        If there is a link preload already in progress, we fail to clear the client for the ongoing load.
+        This may leave the CachedResource client map in a bad state.
+
 2018-05-11  Charles Vazac  <cvazac@gmail.com>
 
         Runtime feature flag for Server-Timing
index 3ba4287..3447776 100644 (file)
@@ -301,10 +301,10 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href,
 
     if (m_client.shouldLoadLink()) {
         auto resourceClient = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, this);
+        if (m_preloadResourceClient)
+            m_preloadResourceClient->clear();
         if (resourceClient)
             m_preloadResourceClient = WTFMove(resourceClient);
-        else if (m_preloadResourceClient)
-            m_preloadResourceClient->clear();
     }
 
     prefetchIfNeeded(relAttribute, href, document);