diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2019-06-28 23:55:47 -0700 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2019-06-28 23:55:47 -0700 |
commit | 6f00330a39ffd9d0a20bc6cc85c49c2977ac9cae (patch) | |
tree | 79dd241ddf57f9ec75ebbfcb177a33ec720c5c3a | |
parent | 4c896cbb31fcb929b0e57c7bd02e519c267a1be1 (diff) |
[ios] Fix a race condition issue in the Mapbox metrics class.
-rw-r--r-- | platform/darwin/src/MGLNetworkConfiguration.m | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/platform/darwin/src/MGLNetworkConfiguration.m b/platform/darwin/src/MGLNetworkConfiguration.m index 40993c97b..8e31e5c37 100644 --- a/platform/darwin/src/MGLNetworkConfiguration.m +++ b/platform/darwin/src/MGLNetworkConfiguration.m @@ -65,9 +65,13 @@ NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace"; } - (void)startDownloadEvent:(NSString *)urlString type:(NSString *)resourceType { - if (urlString && ![self.events objectForKey:urlString]) { - [self.events setObject:@{ MGLStartTime: [NSDate date], MGLResourceType: resourceType } forKey:urlString]; + NSString *retainedUrlString = urlString; + NSString *retainedResourceType = resourceType; + if (retainedUrlString && !self.events[retainedUrlString]) { + self.events[retainedUrlString] = @{ MGLStartTime: [NSDate date], MGLResourceType: retainedResourceType }; } + retainedUrlString = nil; + retainedResourceType = nil; } - (void)stopDownloadEventForResponse:(NSURLResponse *)response { @@ -80,15 +84,16 @@ NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace"; - (void)sendEventForURLResponse:(NSURLResponse *)response withAction:(NSString *)action { - if ([response isKindOfClass:[NSURLResponse class]]) { - NSString *urlString = response.URL.relativePath; + NSURLResponse *retainedResponse = response; + if ([retainedResponse isKindOfClass:[NSURLResponse class]]) { + NSString *urlString = retainedResponse.URL.relativePath; if (urlString && [self.events objectForKey:urlString]) { - NSDictionary *eventAttributes = [self eventAttributesForURL:response withAction:action]; + NSDictionary *eventAttributes = [self eventAttributesForURL:retainedResponse withAction:action]; [self.metricsDelegate networkConfiguration:self didGenerateMetricEvent:eventAttributes]; [self.events removeObjectForKey:urlString]; } } - + retainedResponse = nil; } - (NSDictionary *)eventAttributesForURL:(NSURLResponse *)response withAction:(NSString *)action |