diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm index 8b5ef4902..dd28e0242 100644 --- a/util/net/http_transport_mac.mm +++ b/util/net/http_transport_mac.mm @@ -294,50 +294,62 @@ static bool ExecuteProxyRequest(NSMutableURLRequest* request, NSURLSession* session = [NSURLSession sessionWithConfiguration:sessionConfig]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - [[session dataTaskWithRequest:request - completionHandler:^( - NSData* body, NSURLResponse* response, NSError* error) { - if (error) { - Metrics::CrashUploadErrorCode(error.code); - LOG(ERROR) << [[error localizedDescription] UTF8String] - << " (" << [[error domain] UTF8String] << " " - << [error code] << ")"; - sync_rv = false; - dispatch_semaphore_signal(semaphore); - return; - } - if (!response) { - LOG(ERROR) << "no response"; - sync_rv = false; - dispatch_semaphore_signal(semaphore); - return; - } - auto http_response = - base::apple::ObjCCast(response); - if (!http_response) { - LOG(ERROR) << "no http_response"; - sync_rv = false; - dispatch_semaphore_signal(semaphore); - return; - } - NSInteger http_status = [http_response statusCode]; - if (http_status < 200 || http_status > 203) { - LOG(ERROR) << base::StringPrintf( - "HTTP status %ld", implicit_cast(http_status)); - sync_rv = false; - dispatch_semaphore_signal(semaphore); - return; - } - - if (response_body) { - response_body->assign( - static_cast([body bytes]), [body length]); - } - sync_rv = true; - dispatch_semaphore_signal(semaphore); - }] resume]; - - dispatch_semaphore_wait(semaphore, (dispatch_time_t)(10 * NSEC_PER_SEC)); + NSURLSessionDataTask* task = [session + dataTaskWithRequest:request + completionHandler:^( + NSData* body, NSURLResponse* response, NSError* error) { + if (error) { + Metrics::CrashUploadErrorCode(error.code); + LOG(ERROR) << [[error localizedDescription] UTF8String] << " (" << + [[error domain] UTF8String] << " " << [error code] << ")"; + sync_rv = false; + dispatch_semaphore_signal(semaphore); + return; + } + if (!response) { + LOG(ERROR) << "no response"; + sync_rv = false; + dispatch_semaphore_signal(semaphore); + return; + } + auto http_response = + base::apple::ObjCCast(response); + if (!http_response) { + LOG(ERROR) << "no http_response"; + sync_rv = false; + dispatch_semaphore_signal(semaphore); + return; + } + NSInteger http_status = [http_response statusCode]; + if (http_status < 200 || http_status > 203) { + LOG(ERROR) << base::StringPrintf( + "HTTP status %ld", implicit_cast(http_status)); + sync_rv = false; + dispatch_semaphore_signal(semaphore); + return; + } + + if (response_body) { + response_body->assign(static_cast([body bytes]), + [body length]); + } + sync_rv = true; + dispatch_semaphore_signal(semaphore); + }]; + + if (task == nil) { + LOG(ERROR) << "Failed to create upload task."; + return false; + } + + [task resume]; + + if (0 != + dispatch_semaphore_wait( + semaphore, dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC))) { + LOG(ERROR) << "Upload task semaphore wait timed out"; + sync_rv = false; + } } return sync_rv; }