Since iOS 16.X a lot users get Error Domain=NSURLErrorDomain Code=-1009

We use Rest API POST call to connect to some external Https endpoints. This worked for years, but not clients on 16.2 have the problem that out of a sudden the calls are blocked.

Then nothing works, and our app thinks it's offline (for this call) but it's not offline since other services are. The only wat to fix this is to Restart the app fully. Then it's working for some while.

Is their something changed in IOS 16, that its blocking an endpoint when you do to many calls? It's for prints and pin payment, so we do calls like this continuously.

Here the error we get when it goes wrong:

Failed with error sessionTaskFailed(error: Error Domain=NSURLErrorDomain Code=-1009 "De internetverbinding is offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x282afcc30 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0[802.11], ipv4, dns, _kCFStreamErrorCodeKey=50, 

First we did do the call like this:

                urlRequest.setValue(self.getToken(), forHTTPHeaderField: "Authorization")
                urlRequest.setValue("text/plain", forHTTPHeaderField: "Content-Type")
                urlRequest.addValue("application/json", forHTTPHeaderField: "Accept")
                urlRequest.httpMethod = "POST"
                urlRequest.httpBody = request.data

                let config = URLSessionConfiguration.default
                config.timeoutIntervalForRequest = TimeInterval(5)
                config.timeoutIntervalForResource = TimeInterval(5)
                config.waitsForConnectivity = false

                let session = URLSession(configuration: config)
                let task = session.dataTask(with: urlRequest) { responseData, response, error in
                    var isPosted = false
                    if let err = error {
                        Logger.debug("AWS-Api: \(request.identifer) - Failed with " +
                                     "error \(err), retrying after few seconds")
                        var newReq = request
                        newReq.noRetry += 1
                        self.addRequest(newReq)
                    } else if let resData = responseData, let res = response {
                        isPosted = self.processAWSResponse(request.identifer,
                                                           data: resData,
                                                           postData: request.data,
                                                           response: res)
                    }
                    session.invalidateAndCancel()
                    return promise(.success(isPosted))
                }
                task.resume()
            }

To debug we also updated it and use Alomfire. But unfortunately both dont work. In IOS 15 no problems are their.

All the endpoints are https://

Is their something changed in IOS 16, that its blocking an endpoint when you do to many calls?

I am not aware of any change like this. There are a few place this may be going wrong:

  1. First checkout the server side logs to see if any part of your failed requests are making it to your server. For example, are you receiving data when the request failed? In that case you should have logs on the server indicating the issue.
  2. Possibly you are getting routed to a server that you did not expect. You may also want to checkout your network topology here too.
  3. You're creating a new URLSession object for each iteration of this call. That is generally not a good idea. It should cause the issue you are seeing, but I wanted to mention it to aide your debugging forward.

Hi their.

Thanks for you input and suggestions. To give a response on the suggestion you mention.

First checkout the server side logs to see if any part of your failed requests are making it to your server. For example, are you receiving data when the request failed? In that case you should have logs on the server indicating the issue.

this was indeed our first thought. But the same problem / error appears on two total different endpoints. One AWS webhook and an external API of one of our connected partners.

Possibly you are getting routed to a server that you did not expect. You may also want to checkout your network topology here too.

i will indeed do some research here. We have it on 20+ other clients all on different locations. All on IOS 16. But indeed they have all the same OpenWrt router behind it. We will check if the same problem appears without router.

You're creating a new URLSessionobject for each iteration of this call. That is generally not a good idea. It should cause the issue you are seeing, but I wanted to mention it to aide your debugging forward.

thanks for this tip. To search for a solution we updated this full part of the code with Alomfire to see if it also happens with that. Unfortunately still the same problem.

So there is one thing we are missing here. 😐

The error message you are seeing is indicating that the device is unable to establish a network connection to the specified endpoint. This can be caused by a variety of factors, including network issues, server issues, or changes to the iOS network stack.

One potential cause of this issue could be changes to the iOS network stack that affect how your app is able to establish and maintain connections to external endpoints. This could be related to changes in how the operating system handles network connections, or changes in how your app interacts with the network stack. To troubleshoot this issue, you can try the following steps:

  • Check the network connection: Ensure that the device is connected to a stable network connection, and that other apps on the device are able to access the internet. If the device is not connected to the internet, or the network connection is unstable, this could be causing the error.
  • Review the server logs: Check the logs on the server-side to see if there are any issues with the endpoint that your app is attempting to access. If the server is experiencing issues, this could be causing the error.
  • Increase the timeout interval: Increase the timeout interval for your network requests to give your app more time to establish a connection. You can do this by modifying the URLSessionConfiguration timeoutIntervalForResource and timeoutIntervalForRequest properties.
  • Implement retries: Add retry logic to your app to retry failed network requests. This can help to mitigate issues caused by intermittent network connectivity or server-side issues.
  • Implement a fallback mechanism: If the network request fails, implement a fallback mechanism to handle the error gracefully. This can include showing a message to the user that the app is unable to connect to the endpoint, or falling back to a cached version of the data if available.
  • Update to the latest iOS version: Ensure that your app is running on the latest version of iOS to take advantage of any bug fixes or improvements to the network stack.

If none of these steps resolve the issue, you may need to investigate further by reviewing your app's network code and debugging the issue using tools like Wireshark or Charles Proxy to capture network traffic.

I have the same problem

Since iOS 16.X a lot users get Error Domain=NSURLErrorDomain Code=-1009
 
 
Q