AFNetworking/AFNetworking — pull request #1544 by pavolas (2013-10-26 20:44:36+00:00)
Title: Infinite loop on network thread

Fix a bug where [AFURLConnectionOperation pause] did not correctly reset
the state of AFURLConnectionOperation, causing the Network Thread to
enter an infinite loop.

The logic for 'pause' was calling [self.connection performSelector:...].
If 'pause' is executed immediately after 'start', and 'start' did not
have a chance to create self.connection on the Network Thread, then the
logic in 'pause' would effectively be a no-op. When 'resume' gets
called, the previous connection was not actually cancelled, so there are
2 connections both of which have a reference to the same NSOutputStream.
The first connection to finish/error would close the NSOutputStream, and
the second connection would spin forever in the delegate callback
connection:didReceiveData: since [self.outputStream hasSpaceAvailable]
always returns NO.

The test case I added reproduces the failure, but is flaky because it
relies on a race condition between the main thread and the Network
Thread.