I've been struggling with an HTTP timeout issue recently. After more than one month of investigation I'm quite sure that it is caused by bad HTTP persistent connections. Details are as follows:
NSURLConnection
.keep alive
bug but mine is a different issue. More specifically, that bug causes NSURLErrorNetworkConnectionLost
but my error is NSURLErrorTimedOut
. However, I'm not sure whether my issue is caused by another bug of iOS 8.NSURLErrorTimedOut
, and all following(not too far away from the last one in time to reuse the persistent connection) requests would causes NSURLErrorTimedOut
.NSURLErrorTimedOut
. From the workaround we can see all of them work because they cause the bad persistent connection to be dropped and a new persistent connection to be created.My questions:
NSURLConnection
to not reuse the current persistent connection but to create a new one so I can work around this issue after I detect it in my code?I successfully mitigated this issue on iOS 8 by using CFNetwork
and controlling Connection
header directly. However it seems the issue becomes worse on iOS 9.
Since my hope that Apple would fix it on iOS 9 is broken I finally fired a radar: http://www.openradar.me/22770738.
If you also encounter this issue please duplicate my radar, or even better, fire your own radar if you have a more reliably reproducible sample.
After 2 weeks of research, I can give answers to question 3 and 4:
nginx
's persistent connection timeout is set to 5s on server, which should not be the cause. Server engineers found those timed-out requests are actually normally received and responded. So it is more likely a client side issue. Since I have a minimal reproducible code to rule out my code as the cause, the cause should be in iOS.CFNetwork
. Higher level API such as NSURLConnection
or NSURLSession
's Connection
header will be overwritten by system. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With