Web server KeepAliveTimeout set เป็น 30 วิ แล้ว iphone app จะ happy
(ก่อนนี้ set ไว้ต่ำมาก กลัวจำนวน processes บน server เยอะเกิน แล้ว app error “The network connection was lost” บ่อยๆ
As far as we can tell, when iOS 8 receive an HTTP response with a Keep-Alive header, it keeps this connection to re-use later (as it should), but it keeps it for more than the timeout parameter of the Keep-Alive header and then when a second request comes it tries to re-use a connection that has been dropped by the server.
Here are the solutions we have found so far:
– Increase the timeout parameter of the server above 30 seconds. It looks like iOS is always behaving as if the server will keep the connection open for 30 seconds regardless of the value provided in the Keep-Alive header. (This can be done for Apache by setting the KeepAliveTimeout option.
– You can simply disable the keep alive mechanism for iOS clients based on the User-Agent of your app (e.g. for Apache: BrowserMatch “iOS 8.” nokeepalive in the mod file setenvif.conf)
– If you don’t have access to the server, you can try sending your requests with a Connection: close header: this will tell the server to drop the connection immediately and to respond without any keep alive headers. BUT at the moment, NSURLSession seems to override the Connection header when the requests are sent (we didn’t test this solution extensively as we can tweak the Apache configuration)