Resolve frequent crashes in topPrivatelyControlledDomain
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jun 2019 20:39:29 +0000 (20:39 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jun 2019 20:39:29 +0000 (20:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199072
<rdar://problem/51428162>

Reviewed by Youenn Fablet.

Crash data indicates that we are frequently crashing when multiple threads call
WebCore::topPrivatelyControlledDomain.

Code review showed the potential for a thread contention issue, since WebKit builds
with '--fno-threadsafe-statics'.

This patch corrects the thread safety issue in WebCore::topPrivatelyControlledDomain.

* platform/mac/PublicSuffixMac.mm:
(WebCore::topPrivatelyControlledDomain): Only instantiate the static cache after the
current thread has achieved its lock.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/PublicSuffixMac.mm

index ec3afe4..d6b03f8 100644 (file)
@@ -1,3 +1,23 @@
+2019-06-20  Brent Fulgham  <bfulgham@apple.com>
+
+        Resolve frequent crashes in topPrivatelyControlledDomain
+        https://bugs.webkit.org/show_bug.cgi?id=199072
+        <rdar://problem/51428162>
+
+        Reviewed by Youenn Fablet.
+
+        Crash data indicates that we are frequently crashing when multiple threads call
+        WebCore::topPrivatelyControlledDomain. 
+
+        Code review showed the potential for a thread contention issue, since WebKit builds
+        with '--fno-threadsafe-statics'.
+
+        This patch corrects the thread safety issue in WebCore::topPrivatelyControlledDomain.
+
+        * platform/mac/PublicSuffixMac.mm:
+        (WebCore::topPrivatelyControlledDomain): Only instantiate the static cache after the
+        current thread has achieved its lock.
+
 2019-06-20  Saam Barati  <sbarati@apple.com>
 
         [WHLSL] Property resolver needs to recurse on newValueExpression for RMW operations
index 668dce0..b8506ab 100644 (file)
@@ -50,13 +50,13 @@ String topPrivatelyControlledDomain(const String& domain)
     if (!domain.isAllASCII())
         return domain;
 
-    static NeverDestroyed<HashMap<String, String, ASCIICaseInsensitiveHash>> cache;
     static Lock cacheLock;
-
-    auto isolatedDomain = domain.isolatedCopy();
-
     auto locker = holdLock(cacheLock);
 
+    static NeverDestroyed<HashMap<String, String, ASCIICaseInsensitiveHash>> cache;
+
+    auto isolatedDomain = domain.isolatedCopy();
+    
     constexpr auto maximumSizeToPreventUnlimitedGrowth = 128;
     if (cache.get().size() == maximumSizeToPreventUnlimitedGrowth)
         cache.get().remove(cache.get().random());