Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure NSURLSession request's retry attempts on connection drop?

I'm using NSURLSession for the networking. Testing in Charlesproxy with connections drop shows there are actually three requests are being sent instead of one.

It looks like it is sort of NSURLSession low level work - if it determines connection drop, it will actually send several more requests before deciding there is really no network and calling delegate/block with failure.

Just to prove my assumptions, I changed NSURLSessionConfiguration from defaultSessionConfiguration to backgroundSessionConfigurationWithIdentifier and it started to send even more requests (4) before calling delegate/block.

This is not some issue in my opinion, just wondering wether it can be configured somehow.

like image 899
Nikita Avatar asked Aug 07 '16 14:08

Nikita


1 Answers

I think what you're seeing are artifacts of the way NSURLSession works. It:

  • Simultaneously makes IPv4 and IPv6 connections to the host.
  • Uses the first connection that opens successfully, closing the other connection immediately.
  • Upon failure, tells Reachability to see if it can reach any other servers (e.g. apple.com) to determine which error code to send back.

AFAIK, none of that is configurable, AFAIK.

like image 184
dgatwood Avatar answered Nov 05 '22 07:11

dgatwood