summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2019-06-28 23:55:47 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2019-06-28 23:55:47 -0700
commit6f00330a39ffd9d0a20bc6cc85c49c2977ac9cae (patch)
tree79dd241ddf57f9ec75ebbfcb177a33ec720c5c3a
parent4c896cbb31fcb929b0e57c7bd02e519c267a1be1 (diff)
downloadqtlocation-mapboxgl-6f00330a39ffd9d0a20bc6cc85c49c2977ac9cae.tar.gz
[ios] Fix a race condition issue in the Mapbox metrics class.
-rw-r--r--platform/darwin/src/MGLNetworkConfiguration.m17
1 files changed, 11 insertions, 6 deletions
diff --git a/platform/darwin/src/MGLNetworkConfiguration.m b/platform/darwin/src/MGLNetworkConfiguration.m
index 40993c97b5..8e31e5c37c 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