dataWithContentsOfURL timeout issues
kashifhisam opened this issue · 3 comments
dataWithContentsOfURL does not support timeout. So if internet is choked, then many threads will be started and each one will be waiting for the other to finish. I think it's better to use NSURLConnection's sendSynchronousRequest call.
It's not clear to me that dataWithContentsOfURL is any different from calling sendSynchronousRequest with the default timeout (which is 4 minutes, I think).
It's only called once per session, and it won't block other requests because I'm calling it on a background thread, so I think it's okay.
It would be better to use an async request on the main runloop, but this would substantially complicate the code unless I use a 3rd party network library, which I'd like to avoid.
Yes, you are right that dataWithContentsOfURL may have an internal timeout. Certainly it will not block UI, but iVersion will keep on making new threads when some user exits & relaunch the app during such situation. I think a boolean flag can also do the job so that it does not start a new check in background if existing dataWithContentsOfURL is on wait.
For NSURLConnection, timeout can be specified by using NSURLRequest's requestWithURL:cachePolicy:timeoutInterval: method.
As of version 1.9.4, iVersion sets an explicit 30-second timeout for checks and uses a boolean flag to avoid spawning multiple download threads. Thanks for the suggestion.