AFNetworking/AFNetworking — pull request #1545 by pavolas (2013-10-26 21:36:38+00:00)
Title: Fix a non-deterministic failure in [AFURLConnectionOperation cancel]

Fix a bug where [AFURLConnectionOperation cancel] does not set the appropriate error on the NSOperation.

There is a race condition where 'cancel' is called immediately after
'start'. When operationDidStart is then called on the Network Thread,
self.connection is not instantiated, because the NSOperation is
cancelled, and 'finish' is called, but without the error set. When
cancelConnection is then called on the Network Thread, the error is not
set, because the operation is already finished.

In the new code, cancelConnection is always responsible for setting the error,
and then calling 'finish'. operationDidStart never attempts to call
'finish'.

This bug was one of the sources of non-deterministic failures in
testThatCancellationOfRequestOperationInvokesFailureCompletionBlock.