UploadTask with background, automatic retry request after 70 seconds - why?

I have a question, I'm sending a photo and I'm using uploadTask(withStreamedRequest: request). Request sent correctly, but when duration of request is longer than 67-70 seconds, app automatically performs the same request second time (I see this in Charles Proxy). Regardless of whether the application is in background or in foreground situation is the same. I don't know why request executed second time. Anybody had the same situation?


This is part of my code:


APIClient class: NSObject {
     private let sessionConfig: URLSessionConfiguration = .background (withIdentifier: "background.mode")
     private lazy var urlSession: URLSession = {
         return URLSession (configuration: sessionConfig, delegate: self, delegateQueue: nil)     
     } ()

     override init () {
          super.init ()
          sessionConfig.timeoutIntervalForRequest = 120.0
          sessionConfig.timeoutIntervalForResource = 120.0
     }

     func execute (with request: URLRequest) {
          let task: URLSessionUploadTask
          task = urlSession.uploadTask (withStreamedRequest: request)
          task.resume ()
          ...
     }
}
  • I am seeing similar behavior. A very slow request gets resent about every 70 seconds. Did you ever find a solution to this problem?

Add a Comment