On Nov 22, 2016, at 1:28 PM, Rick Mann < email@hidden> wrote:
FWIW, I'm also setting .httpShouldUsePipelining to true … I commented out all my adjustments and tried just the default URLSessionConfiguration, still the same behavior.
HTTP pipelining is problematic; it was badly designed. I wouldn’t recommend using it. (HTTP/2 does pipelining properly, but I’ve encountered problems using it with NSURLSession, at least in iOS 9.)
• Aside: I was getting the default URLSessionConfiguration and setting these properties. Should I be getting a copy of the default instead?
No need; that method returns a fresh instance every time.
• I'm also worried about the frequent "A server with the specified hostname could not be found" errors I get. Could that be the result of attempts at DNS resolution failing because of too many open files, and being changed into a not-found error? I also get "The Internet connection appears to be offline".
DNS resolution shouldn’t be affected by open sockets/files in your app, since it’s done in another process. These two errors sound like your device’s IP connection is being flaky.
• I don't understand why so many connections are opening, since I am currently limiting it to 4 tasks per session. It seems they're not closing after each use, but not getting re-used?
The sockets do get reused; they’re left open after a request completes, and can then be used to send another request. But the number of sockets per session should be no greater than the limit you specified. (You only open one NSURLSession, right?)
The code I work on uses NSURLSession very heavily, sending hundreds of parallel requests in a typical operation, and we haven’t seen problems on iOS 10. However, we don’t use download tasks, just data tasks.
—Jens |