0

I have an Post Request, that needs to be submit using NSURLSession. Due to some requirement, i have to set the timeout to 230 seconds. So the idea here is, the NSURLSession should wait for 230 seconds until it declares the task as time out issue.

I have done some experiments as -

  1. I set some arbitrary 10 seconds to check timeout issue, work fine.
  2. I set 50 seconds as time out, works fine.
  3. I set 60 seconds (which is default timeout), it again works fine.
  4. I set 75 secods as time out, it also works fine.
  5. But, when i set 76 as time out, the request gets time out in 75 seconds
  6. I set 100 seconds as timeout, but again request gets timeout in 75 seconds.
  7. I set 200 seconds as timeout, again the request gets timeout in 75 seconds.

So is there some undocumented value like maximum timeout available is 75 seconds?

i am setting the timeout in 2 ways

  1. Using timeoutInterval property of NSMutableURLRequest
  2. Using defaultSessionConfiguration properties, timeoutIntervalForRequest and timeoutIntervalForResource

I have used dataTaskWithRequest to POST the service.

So the minimum value takes effect between all the three properties in determining the timeout. And if it is less than 75 seconds, it works fine. But if is greater than 75 seconds, it just ignores it.

Please let me know, what is issue? is 75 seconds is the highest time allocated for timeout or am i missing something here.

P.S. I am executing the task in the main thread and debugging in iOS 9.2. To make things clear, I am checking the timeout while server is not reachable

Pranjal Bikash Das
  • 1,092
  • 9
  • 27
  • What kind of timeout are you testing? Is it an HTTP-level timeout (TCP connection is established, but server waits before returning the response), or a TCP-level timeout (no response to SYN packet, e.g. by sending the request to an IP that no server uses, or with packet filtering)? – jcaron Jan 25 '16 at 13:08
  • Also, when testing via `defaultSessionConfiguration`, you do indeed create a session with the newly-created configuration, right? – jcaron Jan 25 '16 at 13:21
  • yes. i have used the session configuration using `sessionWithConfiguration`. And in my case, i am checking the timeout while server is not reachable. – Pranjal Bikash Das Jan 25 '16 at 15:18
  • 1
    If the server is not reachable, then it's a TCP timeout, not an HTTP timeout. When manipulating sockets directly, this would be set via `setsockopt` with parameter `TCP_CONNECTIONTIMEOUT`, however I don't think you have access to this via `NSURLSession`. The default value comes from `sysctl` setting `net.inet.tcp.keepinit` (which is indeed 75 on Mac OS X, so presumable the same on iOS, too lazy to check). Not sure there is any way to override this from within the app, though. – jcaron Jan 25 '16 at 15:56
  • Thanks. This makes much sense, actually. will try some other things like keeping the server busy while making it reachable and will see if the time out still occur in 75 seconds. However, from `NSURLConnection` point of view, i guess it consider TCP timeout as HTTP timeout only. That's why, in `NSURLConnection` even though i make the server unreachable, the time out occurs at designated time out interval only. – Pranjal Bikash Das Jan 25 '16 at 20:31
  • It's quite weird that `NSURLConnection` handled things differently, I really thought there were built upon the same underlying code. How did you set the timeout value in that case? `NSMutableURLRequest`'s `timeoutInterval` is supposed to be an idle timeout rather than a connection timeout. To make sure the request takes a long time to be answered, just add a big `sleep` in your server-side script (specific details vary based on scripting language, server, etc.) – jcaron Jan 25 '16 at 22:25
  • In case of `NSURLConnection` setting `timeoutInterval` of `NSMutableURLRequest,` pretty much does the work for me. in my case, after successful TCP connection, `NSURLConnection` still wait for the timeout interval to get the resource. If not, will throw error. – Pranjal Bikash Das Jan 27 '16 at 19:35
  • Isn't it the same with `NSURLSession`? Aren't you comparing two different scenarios? – jcaron Jan 27 '16 at 22:43
  • except that, NSURLConnection still wait for given timeout ( which is 75 seconds) even though TCP connection not established or server is unreachable. – Pranjal Bikash Das Jan 28 '16 at 07:01

1 Answers1

0

It may be the case that the 75 seconds is the timeout on the service side.

Gabi D
  • 199
  • 1
  • 8