Known problems with calling [NSURLSessionDataTask cancel]?
Known problems with calling [NSURLSessionDataTask cancel]?
- Subject: Known problems with calling [NSURLSessionDataTask cancel]?
- From: Todd Bogdan (Bogdog™) <email@hidden>
- Date: Tue, 28 Apr 2015 13:29:25 -0700
I'm about to file a Radar on this and wanted to see if there was any guidance on this list. Thanks for looking
I can repro a problem when calling [NSURLSessionDataTask cancel] on a task will prevent other tasks from working after several a canceled. The URLs are hitting a server that supports SPDY. They run in parallel. If some of them get cancelled, the canceled ones seem to leak and requests later just hang and can't be sent.
Example requests.
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
self.downloadSession = session;
- (void)urlSessionRequestWithContentUrl:(NSString *)url size:(NSUInteger)size {
NSString *urlString = [kDownloadImageUrlDomainString stringByAppendingString:url];
urlString = [urlString stringByAppendingFormat:@"s%d", (int)size];
NSURL *imageUrl = [NSURL URLWithString:urlString];
void (^completionHandler)(NSData *, NSURLResponse *, NSError *) =
^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
if (error.code != NSURLErrorCancelled) {
_GTMDevLog(@"NSURLSessionDataTask error %@", error);
} else {
_GTMDevLog(@"NSURLSessionDataTask canceled");
}
} else {
_GTMDevLog(@"NSURLSessionDataTask data %dKb", (int)data.length>>10);
}
};
NSURLRequest *request = [NSURLRequest requestWithURL:imageUrl];
NSURLSessionDataTask *task = [self.downloadSession dataTaskWithRequest:request
completionHandler:completionHandler];
[task resume];
if (size & 1) {
dispatch_queue_t queue = dispatch_get_main_queue();
NSTimeInterval delay = rand();
delay /= (NSTimeInterval)RAND_MAX;
delay *= 5;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), queue, ^{
[task cancel];
});
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden