NSURLErrorCancelled after seemingly successful transfer?

We are using an URLSessionDataTask to download some JSON from a server and lately we sometimes receive NSURLErrorCancelled (code -999) for no apparent reason.

After enabling CFNetwork Diagnostic Logging I found that in these cases the request finishes with the error mentioned above instead of HTTP/1.1 200 OK even though the response body seems to be transferred in its entirety. What could be causing this? I am pretty certain that it is not us cancelling the task.

Answered by jzilske in 903657022

No, but it was started from a SwiftUI view's refreshable(action:) closure. It seems that the task got cancelled because the view got destroyed.

Is this a background session?

Share and Enjoy

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

Accepted Answer

No, but it was started from a SwiftUI view's refreshable(action:) closure. It seems that the task got cancelled because the view got destroyed.

NSURLErrorCancelled after seemingly successful transfer?
 
 
Q