• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Known problems with calling [NSURLSessionDataTask cancel]?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

https://lh3.googleusercontent.com/QO8n3odLN4M1ZkkdFQtWP7hKEaWwdKGppoMQRl4hg2Pm=s128

https://lh3.googleusercontent.com/QO8n3odLN4M1ZkkdFQtWP7hKEaWwdKGppoMQRl4hg2Pm=s129

https://lh3.googleusercontent.com/QO8n3odLN4M1ZkkdFQtWP7hKEaWwdKGppoMQRl4hg2Pm=s130

etc

Simple code that shows this.

    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

  • Prev by Date: Profiling network I/O with Instruments?
  • Next by Date: SCNetworkReachability giving nonsensical results in iOS Simulator
  • Previous by thread: Profiling network I/O with Instruments?
  • Next by thread: SCNetworkReachability giving nonsensical results in iOS Simulator
  • Index(es):
    • Date
    • Thread