Crash when canceling a connection that has finished loading

Issue #2 new
David Roy
created an issue

If you create an NSURLConnection instance and try to cancel it sometime after it has finished NSURLConnectionVCR crashes with an unknown selector for cancel. This is because NSURLConnectionVCR nils out the underlying connection after the data was done loading and has nowhere to forward the cancel method. Test exhibiting the behavior below:

- (void)testCancelingConnection {
    NSError* error = nil;
    STAssertTrue([NSURLConnectionVCR setPath:tapesPath error:&error], @"Expecting VCR to start");
    NSURLRequest* request = [NSURLRequest requestWithURL:testURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
    if ([NSURLConnectionVCR hasCacheForRequest:request]) {
        [NSURLConnectionVCR deleteCacheForRequest:request error:nil];

    ConnectionDelegate *vcrDelegate = [[ConnectionDelegate alloc] init];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:vcrDelegate startImmediately:YES];
    while ([vcrDelegate isDone] == NO) {
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
    [connection cancel];

Comments (1)

  1. Log in to comment