iosswiftnsurlsessionurlsessionnsurlsessiondownloadtask

iOS background download not respecting httpMaximumConnectionsPerHost


I am on iOS 14.2... I have a URLSession that i configure that way:

private lazy var backgroundURLSession: URLSession = {
    let config = URLSessionConfiguration.background(withIdentifier: "background-download")
    
    config.sessionSendsLaunchEvents = true
    config.httpMaximumConnectionsPerHost = 2
    config.timeoutIntervalForRequest = 120
    
    return URLSession(configuration: config, delegate: self, delegateQueue: nil)
}()

I give it like 100 URLs to download

    let downloadTask = session.downloadTask(with: offlineTile.url)
    downloadTask.resume()

and even with httpMaximumConnectionsPerHost = 2 the server gets ALL requests at ONCE... ?!? What could I be doing wrong

One more note: We have a Varnish Cache in the background... and noticed that the behavior differs, if Varnish is set to pipe (no caching)


Solution

  • In our case it was the load balancer of our server that did not properly to it's https termination, which caused iOS to send all requests at basically once.