AFNetworking/AFNetworking — pull request #507 by sptramer (2012-09-10 20:21:46+00:00)
Title: [BUGFIX] Avoid common output stream setup errors, including runloop scheduling

This commit fixes two bugs with setting the output stream on an URLConnectionOperation, one common and one not:

- The less common bug is setting `outputStream` to the same value twice. If this is done then the value of `outputStream` should not be triggered as updated, and there's also a very good chance that the stream should not be closed, either. If this fix isn't appropriate I can back it out.

- The more common (and dangerous) bug is runloop scheduling. Output streams *may* be scheduled in multiple runloops according to the documentation. This can create contention between active runloops for performing operations with the stream. Even worse, if the operation is created on (and the `outputStream` is set on) the main thread, this may block activity ESPECIALLY with networks that have high latency or dropped packets (such as Edge or 3G). Would also cause (possibly severe and hard to diagnose) crashes if an operation were created and scheduled in, say, a callback of another operation.

This fix should resolve some of the "3G crash" issues people seem to experience.