Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request not sent

I'm having a weird problem when i consume my API from my app. Sometimes, for no reason, the request is just not sent, and it fails at the end of the time-out with the following error:

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."

I have tried many API such as NSURLConnection delegates, NSURLSession and NSURLConnection.sendSynchronousRequest without success.

Here is a sample project i have made to highlight the issue. ConnectionBugApp

Here are the steps to reproduce:

  • Run the app in Xcode and stop debug just so the app is on your phone
  • Open the app, click Test Connection (it succeeds, loading wheel stops spinning right after)
  • Go to other apps like facebook/twitter/network games (somes that are a bit heavy) and switch to airplane mode a few times
  • Go back to my app and click Test Connection (loading wheel never stops)

A few details that might help:

  • If I use my server IP instead of my domain name, it succeeds

  • Issue only appears when on the LTE/4G network

Any ideas or workaround would be greatly appreciated ! Feel free to ask for more details.

Thanks

EDIT

I've edited the description a lot since i first posted it (hoping to make it cleaner and clearer), i'm sorry if some answers or comment don't really make sense anymore.

like image 354
streem Avatar asked Jul 20 '15 20:07

streem


2 Answers

I have come across this issue when using an asynchronous request. It seems as though iOS limits the number of open connections to a single domain, such that all subsequent connections fail in the manner you have described.

If connections typically complete quickly, this possibly won't be an issue.

The solution is to limit the number of open connections to the same domain to prevent this from happening.

The answer posted by karlos works because the synchronisity of the connection blocks others from being opened.

like image 192
djbp Avatar answered Oct 21 '22 06:10

djbp


Like mentioned in comments, I had DNSSEC (cache poisoning protection) enabled on my hosting service.

Disabling it, fixed the issue, even though that might not be a really nice solution. After a few weeks of searching, that'll be good enough.

I'll give the bounty to someone that can explain it, or who can provide a better solution.

like image 30
streem Avatar answered Oct 21 '22 05:10

streem