-
Re: Is it safe to retry -1005 error code on network request
eskimo Nov 21, 2016 1:50 AM (in response to james8912)Does either of these error codes along with status code 0 guarantee the request never hit the server and therefore always safe to perform a retry …
Error -1005 is
NSURLErrorNetworkConnectionLost
and it’s definitely not safe to retry non-idempotent requests in that case. This error indicates that the TCP connection carrying the HTTP request tore before we got the response. There’s two possibilities:The request did not make it to the server.
The request made it to the server but the response didn’t make it back to the client.
In the second case a blind retry will cause problems. To avoid this, you must implement app-specific logic to query the server to see if the first request made it.
In contrast, error -1009 is
NSURLErrorNotConnectedToInternet
, which means the request probably didn’t make it off the device. However, given that you have to implement app-specific recovery logic to handleNSURLErrorNetworkConnectionLost
, it’s better IMO to ignore the specific error code and use that logic always.Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: Is it safe to retry -1005 error code on network request
james8912 Dec 7, 2016 3:45 AM (in response to eskimo)Thanks Eskimo. Along the same lines, is it safe or not to blindly retry on error codes -1001 and –1003?
-
Re: Is it safe to retry -1005 error code on network request
james8912 Dec 7, 2016 3:48 AM (in response to james8912)And one other question, when a server response has a connection header of "keep-alive, close" it causes -1005 errors for requests. How would you expect iOS NSURLSession to interpret such a response? My expectation would be that it would close the connection.
-
Re: Is it safe to retry -1005 error code on network request
eskimo Dec 7, 2016 6:50 AM (in response to james8912)is it safe or not to blindly retry on error codes -1001 and –1003?
Let’s break this down by code:
NSURLErrorTimedOut
(-1001) — It’s definitely not safe to retry this one. It shows up in all sorts of situations but one common case is that the client sends a request to the server and the server just doesn’t respond. Eventually the client times out with this error, and it’s impossible to know whether the server acted on the request.NSURLErrorCannotFindHost
(-1003) — It should be safe to automatically retry this one; if the client couldn’t find the host, it can’t possibly have sent the request to it.
when a server response has a connection header of "keep-alive, close" it causes -1005 errors for requests.
I wouldn’t expect that. Normally the client knows whether the response is complete or not based on HTTP 1.1 framing, so values in the
Connection
header shouldn’t triggerNSURLErrorNetworkConnectionLost
. I suspect that the server isn’t doing HTTP 1.1 properly, but that’s just a guess; you’d have to have a detailed look at the packets on the wire to see what’s happening here.Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: Is it safe to retry -1005 error code on network request
james8912 Dec 7, 2016 12:58 PM (in response to eskimo)Thanks again for your insights.
-
Re: Is it safe to retry -1005 error code on network request
james8912 Dec 7, 2016 2:25 PM (in response to james8912)Are there any guidelines on configuring a web server to correctly interact with an iOS client in relation to keep-alives? Just that others are reporting similar issues on StackOverflow e.g. http://stackoverflow.com/questions/25372318/error-domain-nsurlerrordomain-code-1005-the-network-connection-was-lost
-
Re: Is it safe to retry -1005 error code on network request
eskimo Dec 11, 2016 3:02 PM (in response to james8912)If you’re talking about an HTTP 1.1 server then iOS expects the server to following the rules defined in RFC 7230 and friends. No specific configuration should be required. If the server is following the RFCs and iOS is still generated unexpected
NSURLErrorNetworkConnectionLost
errors, that’s a bug that needs to be investigated.Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
-
-
-