From 6a6862c43b735f3b9d12a273d7774c5a68bf7532 Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Sun, 21 Apr 2013 18:07:46 +0200 Subject: [PATCH] Workaround for #907. --- AFNetworking/AFHTTPClient.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index e23f2a0..683326f 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -1114,8 +1114,21 @@ static const NSUInteger AFMultipartBodyStreamProviderDefaultBufferLength = 4096; } - (void)close { - [_outputStream close]; - _outputStream.delegate = nil; + NSOutputStream *outputStream = self.outputStream; + + [outputStream close]; + outputStream.delegate = nil; + + /* + Workaround for a race condition in CFStream _CFStreamCopyRunLoopsAndModes. This outputstream needs to be retained just a little longer. + + See: https://github.com/AFNetworking/AFNetworking/issues/907 + */ + double delayInSeconds = 2.0; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_main_queue(), ^{ + outputStream.delegate = nil; + }); _self = nil; }