{"action":"created","issue":{"url":"https://api.github.com/repos/AFNetworking/AFNetworking/issues/2597","labels_url":"https://api.github.com/repos/AFNetworking/AFNetworking/issues/2597/labels{/name}","comments_url":"https://api.github.com/repos/AFNetworking/AFNetworking/issues/2597/comments","events_url":"https://api.github.com/repos/AFNetworking/AFNetworking/issues/2597/events","html_url":"https://github.com/AFNetworking/AFNetworking/issues/2597","id":61682476,"number":2597,"title":"Crash in -[AFURLSessionManager uploadTaskWithStreamedRequest:progress:completionHandler:]","user":{"login":"blixt","id":158591,"avatar_url":"https://avatars.githubusercontent.com/u/158591?v=3","gravatar_id":"","url":"https://api.github.com/users/blixt","html_url":"https://github.com/blixt","followers_url":"https://api.github.com/users/blixt/followers","following_url":"https://api.github.com/users/blixt/following{/other_user}","gists_url":"https://api.github.com/users/blixt/gists{/gist_id}","starred_url":"https://api.github.com/users/blixt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blixt/subscriptions","organizations_url":"https://api.github.com/users/blixt/orgs","repos_url":"https://api.github.com/users/blixt/repos","events_url":"https://api.github.com/users/blixt/events{/privacy}","received_events_url":"https://api.github.com/users/blixt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-03-14T19:24:35Z","updated_at":"2015-03-26T22:55:18Z","closed_at":null,"body":"This happened when I tried to upload a file with a reference to an `NSProgress` pointer to track progress (the pointer was set to `nil` at the time).\r\n\r\nThis is the code that makes the call into AFNetworking:\r\n\r\n```obj-c\r\n- (void)uploadAudioURL:(NSURL *)audioURL\r\n                  path:(NSString *)path\r\n            parameters:(NSDictionary *)parameters\r\n              progress:(NSProgress *__autoreleasing *)progress\r\n               success:(SuccessCallback)success\r\n               failure:(FailureCallback)failure\r\n{\r\n    UIApplication *application = [UIApplication sharedApplication];\r\n    UIBackgroundTaskIdentifier task = [application beginBackgroundTaskWithExpirationHandler:^{\r\n        NSLog(@\"WARNING: Failed to upload audio in time.\");\r\n        [application endBackgroundTask:task];\r\n    }];\r\n\r\n    NSString *url = [[NSURL URLWithString:path relativeToURL:self.manager.baseURL] absoluteString];\r\n\r\n    void (^block)(id<AFMultipartFormData>) = ^void(id<AFMultipartFormData> formData) {\r\n        // Add the audio data to the request.\r\n        [formData appendPartWithFileURL:audioURL name:@\"audio\" error:nil];\r\n    };\r\n\r\n    NSMutableURLRequest *request = [self.manager.requestSerializer multipartFormRequestWithMethod:@\"POST\"\r\n                                                                                        URLString:url\r\n                                                                                       parameters:parameters\r\n                                                                        constructingBodyWithBlock:block\r\n                                                                                            error:nil];\r\n\r\n    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];\r\n    NSURLSessionUploadTask *upload = [manager uploadTaskWithStreamedRequest:request progress:progress completionHandler:^(NSURLResponse *response, id data, NSError *error) {\r\n        if (error) {\r\n            NSLog(@\"WARNING: Failed to upload audio (%@)\", error.localizedDescription);\r\n            NSInteger statusCode = -1;\r\n            if ([response isKindOfClass:[NSHTTPURLResponse class]]) {\r\n                statusCode = ((NSHTTPURLResponse *)response).statusCode;\r\n            }\r\n            failure(statusCode, error);\r\n        } else {\r\n            NSLog(@\"Completed upload of audio\");\r\n            success(data);\r\n        }\r\n        [application endBackgroundTask:task];\r\n    }];\r\n\r\n    [upload resume];\r\n}\r\n```\r\n\r\nThis is the exception: `EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x2b08060143070600`\r\n\r\nCall stack:\r\n\r\n```\r\nThread : Crashed: com.apple.main-thread\r\n0  libobjc.A.dylib                0x00000001984b3bdc objc_msgSend + 28\r\n1  Foundation                     0x00000001882fc2f4 NSKeyValuePushPendingNotificationPerThread + 340\r\n2  Foundation                     0x00000001882e94fc NSKeyValueWillChange + 560\r\n3  Foundation                     0x00000001882d3188 -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:] + 224\r\n4  Foundation                     0x00000001884b3ec4 -[NSProgress _setValueForKeys:settingBlock:] + 292\r\n5  Foundation                     0x00000001884b4230 -[NSProgress setTotalUnitCount:] + 244\r\n6  Foundation                     0x00000001884b2e88 +[NSProgress progressWithTotalUnitCount:] + 116\r\n7  Roger                          0x0000000100081178 -[AFURLSessionManagerTaskDelegate init] (AFURLSessionManager.m:128)\r\n8  Roger                          0x0000000100083964 -[AFURLSessionManager addDelegateForUploadTask:progress:completionHandler:] (AFURLSessionManager.m:464)\r\n9  Roger                          0x00000001000851b4 -[AFURLSessionManager uploadTaskWithStreamedRequest:progress:completionHandler:] (AFURLSessionManager.m:658)\r\n10 Roger                          0x0000000100060e94 -[RogerAPI uploadAudioURL:path:parameters:progress:success:failure:] (RogerAPI.m:266)\r\n11 Roger                          0x00000001000603f8 -[RogerAPI sendMessageToAccount:audioURL:progress:success:failure:] (RogerAPI.m:176)\r\n12 Roger                          0x0000000100062768 -[RogerContact messageWithAudioURL:progress:callback:] (RogerContact.m:127)\r\n13 Roger                          0x0000000100052704 -[RogerTableViewCell endRecording] (RogerTableViewCell.m:216)\r\n14 Roger                          0x0000000100059cb0 -[InboxTableViewController handleLongPress:] (InboxTableViewController.m:157)\r\n15 UIKit                          0x000000018be6f648 _UIGestureRecognizerSendActions + 276\r\n16 UIKit                          0x000000018bd07d30 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 580\r\n17 UIKit                          0x000000018c175574 ___UIGestureRecognizerUpdate_block_invoke662 + 60\r\n18 UIKit                          0x000000018bccc38c _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 292\r\n19 UIKit                          0x000000018bcca738 _UIGestureRecognizerUpdate + 2504\r\n20 UIKit                          0x000000018bd05ed8 -[UIWindow _sendGesturesForEvent:] + 1044\r\n21 UIKit                          0x000000018bd05578 -[UIWindow sendEvent:] + 660\r\n22 UIKit                          0x000000018bcd8e60 -[UIApplication sendEvent:] + 264\r\n23 UIKit                          0x000000018bf7846c _UIApplicationHandleEventFromQueueEvent + 15220\r\n24 UIKit                          0x000000018bcd73d0 _UIApplicationHandleEventQueue + 1716\r\n25 CoreFoundation                 0x0000000187482d34 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24\r\n26 CoreFoundation                 0x0000000187481fd8 __CFRunLoopDoSources0 + 264\r\n27 CoreFoundation                 0x0000000187480088 __CFRunLoopRun + 712\r\n28 CoreFoundation                 0x00000001873ad1f4 CFRunLoopRunSpecific + 396\r\n29 GraphicsServices               0x00000001907cf6fc GSEventRunModal + 168\r\n30 UIKit                          0x000000018bd3e10c UIApplicationMain + 1488\r\n31 Roger                          0x0000000100061624 main (main.m:6)\r\n32 libdyld.dylib                  0x0000000198b1ea08 start + 4\r\n```"},"comment":{"url":"https://api.github.com/repos/AFNetworking/AFNetworking/issues/comments/86746251","html_url":"https://github.com/AFNetworking/AFNetworking/issues/2597#issuecomment-86746251","issue_url":"https://api.github.com/repos/AFNetworking/AFNetworking/issues/2597","id":86746251,"user":{"login":"cesarvilera","id":6886451,"avatar_url":"https://avatars.githubusercontent.com/u/6886451?v=3","gravatar_id":"","url":"https://api.github.com/users/cesarvilera","html_url":"https://github.com/cesarvilera","followers_url":"https://api.github.com/users/cesarvilera/followers","following_url":"https://api.github.com/users/cesarvilera/following{/other_user}","gists_url":"https://api.github.com/users/cesarvilera/gists{/gist_id}","starred_url":"https://api.github.com/users/cesarvilera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cesarvilera/subscriptions","organizations_url":"https://api.github.com/users/cesarvilera/orgs","repos_url":"https://api.github.com/users/cesarvilera/repos","events_url":"https://api.github.com/users/cesarvilera/events{/privacy}","received_events_url":"https://api.github.com/users/cesarvilera/received_events","type":"User","site_admin":false},"created_at":"2015-03-26T22:55:18Z","updated_at":"2015-03-26T22:55:18Z","body":"I'm having the same problem when using backgroundSession... if I change it for defaultSession the problem stops... \r\n\r\nI'm also having another problem with this method, the content-length sent by the app is a little bit smaller than the real one.\r\n\r\nApp Content-Length: 198379 (I'm using OWASP ZAP as a proxy)\r\nReal Content-Length: 204169\r\n\r\nHere is my code.\r\n\r\n```objective-c\r\n-(void)uploadFile:(Files *)file start:(BOOL)start {\r\n    NSString *URLString = [NSString stringWithFormat:@\"%@%@\",self.backgroundNetwork.baseURL,[Files getURL]];\r\n    NSData *fileData = UIImageJPEGRepresentation(file.files_images.image, 1.0);\r\n    NSMutableURLRequest *request;\r\n    request = [[AFJSONRequestSerializer serializer] multipartFormRequestWithMethod:@\"POST\"\r\n                                                                         URLString:URLString\r\n                                                                        parameters:@{@\"name\":file.name}\r\n                                                         constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {\r\n                                                                                  \r\n        [formData appendPartWithFileData:fileData\r\n                                    name:@\"file\"\r\n                                fileName:@\"file.jpg\"\r\n                                mimeType:@\"image/jpeg\"];\r\n                                                                                  \r\n    } error:nil];\r\n    \r\n    NSURLSessionUploadTask *task;\r\n    task = [self.backgroundNetwork uploadTaskWithStreamedRequest:request\r\n                                                        progress:nil\r\n                                               completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {\r\n        \r\n    }];\r\n\r\n    [task resume];\r\n}\r\n```"}}