CFNetwork crash on proxy auto-discovery with iOS 10.2

Number:rdar://29948303 Date Originated:2017/01/10
Status:Open Resolved:
Product:iOS + SDK Product Version:10.2
Classification: Reproducible:Sometimes
CFNetwork Framework

When using CFNetwork to make an HTTP request in order to have a controllable readable stream, if the stream is configured to use system proxy settings, opening the stream leads to application crash. Example code:

// Create http request
let message = CFHTTPMessageCreateRequest(kCFAllocatorDefault, "GET", self.url, kCFHTTPVersion1_1).takeRetainedValue()

// Create stream
let readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, message).takeRetainedValue()

// Set stream properties
CFReadStreamSetProperty(readStream, NSStreamNetworkServiceTypeBackground, NSStreamNetworkServiceTypeBackground)
CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue)

// Configure proxy
if let proxySettings = CFNetworkCopySystemProxySettings()?.takeRetainedValue() {
    CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPProxy, proxySettings)

Steps to Reproduce:
1. Configure proxy auto-discovery url in iOS settings
2. Configure a CFReadStream to use system proxy settings
3. Open the stream


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!