I'm trying to display a `UIAlertView` with `UIActivityIndicator` after a user presses "log in" in a modal view controller. To log in, the credentials are sent to a server using `sendAsynchronousRequest:queue:completionHandler:` from the `NSURLConnection` class. My implementation is as follows:

```
UIAlertView * spinner = [[UIAlertView alloc] initWithTitle:@"Connecting to server..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[spinner show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(spinner.bounds.size.width * 0.5f, spinner.bounds.size.height * 0.5f+5.0f);
[indicator startAnimating];
[spinner addSubview:indicator];
[indicator release];

[NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * res, NSData * data, NSError * err) {
    [spinner dismissWithClickedButtonIndex:0 animated:YES];
    [spinner release];
    ...
}

```

This seems to work fine if the server can't be reached or the server is slow, but if the server replies immediatly, the spinner doesn't seem to be dismissed until after 3-5 seconds with the console logging

```
wait_fences: failed to receive reply: 10004003

```

I think this happens because I'm dismissing a modal view controller (the log in screen) while the `UIAlertView` is still showing but I'm not sure why this happens as it should normally be dismissed. Am I doing something wrong and what would be the correct way of doing this?