Using NSURLSessionDownloadTask to download https file, error is reported Error Domain=kCFErrorDomainCFNetwork Code=303

I use NSURLSessionDownloadTask to download the https file in the background, an error occurs with the error message:

Task .<17> finished with error [303] Error Domain=kCFErrorDomainCFNetwork Code=303 "(null)" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=BackgroundDownloadTask .<17>, _kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey={length = 16, bytes = 0x100201bb17485a920000000000000000}, _kCFStreamErrorCodeKey=-2201, _NSURLErrorRelatedURLSessionTaskErrorKey=(   "BackgroundDownloadTask .<17>",   "LocalDownloadTask .<17>" )}

This error don't occur every time, but the probability is quite high, what is the cause of this error? Please help!

That’s an interesting error. Error 303 in the kCFErrorDomainCFNetwork domain is kCFErrorHTTPParseFailure. The underlying error, -2201, is an internal error that roughly translates to ‘HTTP/2 internal error’. It would seem that something has gone wrong at the HTTP/2 layer and that’s triggering this failure.

This error don't occur every time, but the probability is quite high

My experience with errors like this is that they are most commonly caused by problems on the server. CFNetwork tends to be pretty consistent here, that is, it either works or it fails. Weird intermittent errors tend to occur server side because of various middleboxes, most notably, redirectors.

However, proving that can be a challenge. Is this a server that you control? Or is it run by some unrelated organisation?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hey Eskimo,

The server is Akamai CDN. We think we find the root reason, looks like the TCP window size for the request is just 2KB, it's not able to hold the data from server, then the error occurs.

The small window size introduces two problems for us: 1: The error 2: The download speed is not ideal ( We captured the net traffic, looks like the window size increases very slow, 2KB -> 4KB -> 6KB, we get maximum size 400KB. But for libCurl, it provides an initial 64KB window size and bump to 128KB immediately, the max size reaches to 1700KB ). Are we able to adjust the TCP windows for background download task?

I found you've answered the question 5 years ago, https://developer.apple.com/forums/thread/93736 It was not able to be controlled by developer, but not sure whether it's been enhanced right now.

Thanks

Are we able to adjust the TCP windows for background download task?

There is no specific API to control this on the client side. Check with your server side team as they may be able to assist with controlling window updates for H2 on the server as well.

Hey Meaton, I didn't make it clear, the size we want to control is "client TCP window size", rather than the "server TCP window size" or "H2". We used libCurl to test and get an initial 64KB client TCP window size which is much bigger than "BackgroundDownloadTask".

Using NSURLSessionDownloadTask to download https file, error is reported Error Domain=kCFErrorDomainCFNetwork Code=303
 
 
Q