4

I'm having an issue that's incredibly hard to debug. If my app is using WiFi and it sits idle for around 30 minutes, sometimes when I wake it up, the NSURLConnection no longer responds. Requests are sent, but never return.

At first, I thought this was a memory bug with the instances being released too early and thus never returning a response. However, if I put the app in the background, go into settings, turn off WiFi so 3G is used exclusively, and return to the app, the internet connection magically comes back to life and all pending NSURLConnections return and complete.

Obviously this is an issue for people using WiFi. Is this really a WiFi issue, or am I missing something? Going to another app like Safari, using the WiFi radio and returning to my app doesn't solve the problem - connections still don't return. I've traced this with Xcode and I'm running out of ideas.

Also 'Application Uses WiFi' Info.plist flag is set to ON and this is firmware 5.1. is 'Application Uses WiFi' the same as UIRequiresPersistentWiFi?

Update: This has nothing to do with the Wifi flag - it can die within 5 minutes. So far, I've only been able to duplicate it on my iPhone 4s with 5.1 firmware. It's not really a solution, but I'm erasing the phone to try it with a fresh install to see if that has any effect. I have verified that NSURLConnection is always called on the main thread, and set breakpoints at connection:failedWithError: and connection:didReceiveResponse:. When the connection dies, none of these return until I disable and re-enable WiFi, and then all return at once. This happens on a local server as well, and the server still returns if I ping it with a web browser.

Conrad Shultz
  • 8,748
  • 2
  • 31
  • 33
Shaun Budhram
  • 3,690
  • 4
  • 30
  • 41
  • 1
    Have you tried setting the `UIRequiresPersistentWiFi` flag? – esqew Apr 14 '12 at 05:57
  • I think so - 'Application Uses WiFi' is on in the pList file. – Shaun Budhram Apr 14 '12 at 06:03
  • Are you inadvertently blocking the main thread? Did you try using synchronous NSURLConnections in a background thread? – magma Apr 17 '12 at 02:39
  • Yeah I'm pretty sure the main thread is not blocked, because my app is still responsive and I can switch tabs. I will try the synchronous connections in background threads next. – Shaun Budhram Apr 18 '12 at 19:11

2 Answers2

3

For any others running into this issue, it's due to TestFlight v1.0 and below:

Why does NSURLConnection fail to reach the backend?

Community
  • 1
  • 1
Shaun Budhram
  • 3,690
  • 4
  • 30
  • 41
0

Are you actually transmitting/receiving any data through the NSURLConnection? If not, is it possible you are hitting a TCP session timeout? Seems unlikely if the problem persists on a local server, but any intervening stateful firewall/packet inspector might be casting off your TCP connection.

Conrad Shultz
  • 8,748
  • 2
  • 31
  • 33
  • I was thinking it was possible that I'm somehow not actually submitting the NSURLConnection in certain cases, since I am subclassing. I will look into it. Maybe testing without subclassing might fix it. Thanks for the suggestion. – Shaun Budhram Apr 18 '12 at 19:10