Title: [281486] trunk/Source/WebCore
Revision
281486
Author
commit-qu...@webkit.org
Date
2021-08-23 20:38:06 -0700 (Mon, 23 Aug 2021)

Log Message

ThreadSanitizer: data race of WTF::StringImpl in WebCoreNSURLSessionDataTask._metrics instance variable
https://bugs.webkit.org/show_bug.cgi?id=229435

Patch by Alex Christensen <achristen...@webkit.org> on 2021-08-23
Reviewed by David Kilzer.

Move the isolated copy to the WebCoreNSURLSessionTaskMetrics instead of keeping a copy on the delegate thread
and a copy on whatever thread our media stack wants to use the WebCoreNSURLSessionTaskMetrics on.

* platform/network/cocoa/WebCoreNSURLSession.mm:
(-[WebCoreNSURLSessionTaskTransactionMetrics _initWithMetrics:]):
(-[WebCoreNSURLSessionTaskMetrics _initWithMetrics:]):
(-[WebCoreNSURLSessionDataTask _resource:loadFinishedWithError:metrics:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281485 => 281486)


--- trunk/Source/WebCore/ChangeLog	2021-08-24 02:59:56 UTC (rev 281485)
+++ trunk/Source/WebCore/ChangeLog	2021-08-24 03:38:06 UTC (rev 281486)
@@ -1,3 +1,18 @@
+2021-08-23  Alex Christensen  <achristen...@webkit.org>
+
+        ThreadSanitizer: data race of WTF::StringImpl in WebCoreNSURLSessionDataTask._metrics instance variable
+        https://bugs.webkit.org/show_bug.cgi?id=229435
+
+        Reviewed by David Kilzer.
+
+        Move the isolated copy to the WebCoreNSURLSessionTaskMetrics instead of keeping a copy on the delegate thread
+        and a copy on whatever thread our media stack wants to use the WebCoreNSURLSessionTaskMetrics on.
+
+        * platform/network/cocoa/WebCoreNSURLSession.mm:
+        (-[WebCoreNSURLSessionTaskTransactionMetrics _initWithMetrics:]):
+        (-[WebCoreNSURLSessionTaskMetrics _initWithMetrics:]):
+        (-[WebCoreNSURLSessionDataTask _resource:loadFinishedWithError:metrics:]):
+
 2021-08-23  John Wilander  <wilan...@apple.com>
 
         PCM: Support ephemeral measurement with non-persistent WebCore::PrivateClickMeasurement

Modified: trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm (281485 => 281486)


--- trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm	2021-08-24 02:59:56 UTC (rev 281485)
+++ trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm	2021-08-24 03:38:06 UTC (rev 281486)
@@ -54,7 +54,7 @@
 }
 
 @interface WebCoreNSURLSessionTaskTransactionMetrics : NSObject
-- (instancetype)_initWithMetrics:(const WebCore::NetworkLoadMetrics&)metrics;
+- (instancetype)_initWithMetrics:(WebCore::NetworkLoadMetrics&&)metrics;
 @property (nullable, copy, readonly) NSDate *fetchStartDate;
 @property (nullable, copy, readonly) NSDate *domainLookupStartDate;
 @property (nullable, copy, readonly) NSDate *domainLookupEndDate;
@@ -79,7 +79,7 @@
     WebCore::NetworkLoadMetrics _metrics;
 }
 
-- (instancetype)_initWithMetrics:(const WebCore::NetworkLoadMetrics&)metrics
+- (instancetype)_initWithMetrics:(WebCore::NetworkLoadMetrics&&)metrics
 {
     if (!(self = [super init]))
         return nil;
@@ -206,7 +206,7 @@
 @end
 
 @interface WebCoreNSURLSessionTaskMetrics : NSObject
-- (instancetype)_initWithMetrics:(const WebCore::NetworkLoadMetrics&)metrics;
+- (instancetype)_initWithMetrics:(WebCore::NetworkLoadMetrics&&)metrics;
 @property (copy, readonly) NSArray<NSURLSessionTaskTransactionMetrics *> *transactionMetrics;
 @end
 
@@ -214,11 +214,11 @@
     RetainPtr<WebCoreNSURLSessionTaskTransactionMetrics> _transactionMetrics;
 }
 
-- (instancetype)_initWithMetrics:(const WebCore::NetworkLoadMetrics&)metrics
+- (instancetype)_initWithMetrics:(WebCore::NetworkLoadMetrics&&)metrics
 {
     if (!(self = [super init]))
         return nil;
-    _transactionMetrics = adoptNS([[WebCoreNSURLSessionTaskTransactionMetrics alloc] _initWithMetrics:metrics]);
+    _transactionMetrics = adoptNS([[WebCoreNSURLSessionTaskTransactionMetrics alloc] _initWithMetrics:WTFMove(metrics)]);
     return self;
 }
 
@@ -941,11 +941,11 @@
     RetainPtr<WebCoreNSURLSessionDataTask> strongSelf { self };
     RetainPtr<WebCoreNSURLSession> strongSession { self.session };
     RetainPtr<NSError> strongError { error };
-    [self.session addDelegateOperation:[strongSelf, strongSession, strongError, metrics = metrics.isolatedCopy()] {
+    [self.session addDelegateOperation:[strongSelf, strongSession, strongError, metrics = metrics.isolatedCopy()] () mutable {
         id<NSURLSessionTaskDelegate> delegate = (id<NSURLSessionTaskDelegate>)strongSession.get().delegate;
 
         if ([delegate respondsToSelector:@selector(URLSession:task:didFinishCollectingMetrics:)])
-            [delegate URLSession:(NSURLSession *)strongSession.get() task:(NSURLSessionDataTask *)strongSelf.get() didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)adoptNS([[WebCoreNSURLSessionTaskMetrics alloc] _initWithMetrics:metrics]).get()];
+            [delegate URLSession:(NSURLSession *)strongSession.get() task:(NSURLSessionDataTask *)strongSelf.get() didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)adoptNS([[WebCoreNSURLSessionTaskMetrics alloc] _initWithMetrics:WTFMove(metrics)]).get()];
 
         if ([delegate respondsToSelector:@selector(URLSession:task:didCompleteWithError:)])
             [delegate URLSession:(NSURLSession *)strongSession.get() task:(NSURLSessionDataTask *)strongSelf.get() didCompleteWithError:strongError.get()];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to