Skip to content

Commit

Permalink
Make sure dispatch_semaphore_signal is called when request errors
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus committed May 22, 2023
1 parent 3bc2282 commit af58387
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions util/net/http_transport_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key {
[NSURLSessionConfiguration ephemeralSessionConfiguration];

if (!http_proxy().empty()) {
std::string proxy = http_proxy() + "/";
std::string scheme, host, port, rest_ignored;
CrackURL(http_proxy(), &scheme, &host, &port, &rest_ignored);
CrackURL(proxy, &scheme, &host, &port, &rest_ignored);
NSString* schemeNS = base::SysUTF8ToNSString(scheme);
NSString* hostNS = base::SysUTF8ToNSString(host);
NSNumber* proxy_port = @(std::stoi(port));
Expand All @@ -260,6 +261,9 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key {
(__bridge id)kCFNetworkProxiesHTTPEnable : @YES,
(__bridge id)kCFNetworkProxiesHTTPPort : proxy_port,
(__bridge id)kCFNetworkProxiesHTTPProxy : hostNS,
(__bridge id)kCFNetworkProxiesHTTPSEnable : @YES,
(__bridge id)kCFNetworkProxiesHTTPSPort : proxy_port,
(__bridge id)kCFNetworkProxiesHTTPSProxy : hostNS,
};
sessionConfig.connectionProxyDictionary = proxyDict;
}
Expand All @@ -277,25 +281,29 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key {
<< " (" << [[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;
}
NSHTTPURLResponse* http_response =
auto http_response =
base::mac::ObjCCast<NSHTTPURLResponse>(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<long>(http_status));
sync_rv = false;
dispatch_semaphore_signal(semaphore);
return;
}

Expand All @@ -307,7 +315,7 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key {
dispatch_semaphore_signal(semaphore);
}] resume];

dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(semaphore, (dispatch_time_t)(10 * NSEC_PER_SEC));
}

return sync_rv;
Expand Down

0 comments on commit af58387

Please sign in to comment.