Apollo-ios: Timeout take to much time around 30 seconds

Created on 20 Aug 2017  路  8Comments  路  Source: apollographql/apollo-ios

Please i need your support

I am using apollo and all work great but when i turn down my server for test time out error and connection, i have to different responses from the log.

Most of the times y make fech and apollo take around 30 seconds and show me below error.

timeout

How i can configure time for timeout error nad why take to long.

And some times i receive below response

serverconect

This response is very fast , but is not consistent .
For remark the two response i have the server down.

Please i need your support let me know any feedback that you need.

Thanks.

Most helpful comment

@andrewnorris97 you need to do something like:

let url = URL(string: "http://localhost:8080/graphql")!

var configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 10.0
configuration.timeoutIntervalForResource = 10.0

let networkTransport = HTTPNetworkTransport(url: url, configuration: configuration)

let apollo = ApolloClient(networkTransport: networkTransport)

@horaciosolorio You have a fill opened issues, please close the ones that are resolved :)

All 8 comments

I don't understand how to use timeout interval since we are not creating an NSURLRequest we are creating a GraphQLQuery and passing it into a fetch method along with a cachePolicy, queue and result handler. Where would we define a timeout interval? The fetch is handled by the Apollo framework, we are not creating our own request. Thanks for the help in advance.

@andrewnorris97 you need to do something like:

let url = URL(string: "http://localhost:8080/graphql")!

var configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 10.0
configuration.timeoutIntervalForResource = 10.0

let networkTransport = HTTPNetworkTransport(url: url, configuration: configuration)

let apollo = ApolloClient(networkTransport: networkTransport)

@horaciosolorio You have a fill opened issues, please close the ones that are resolved :)

The URLSessionConfiguration is the correct place to set this timeout interval for now.

Closing this issue, please let me know if you have further questions!

@designatednerd

The URLSessionConfiguration is the correct place to set this timeout interval for now.

Closing this issue, please let me know if you have further questions!

From my investigations when a URLRequest is manually instantiated the timeoutIntervalForRequest from the configuration is ignored. You can see this behavior using the pre-flight delegate.

From: https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration in regards to NSURLSessionConfiguration

In some cases, the policies defined in this configuration may be overridden by policies specified by an NSURLRequest object provided for a task. Any policy specified on the request object is respected unless the session鈥檚 policy is more restrictive. For example, if the session configuration specifies that cellular networking should not be allowed, the NSURLRequest object cannot request cellular networking.

Another reference of this issue: https://stackoverflow.com/questions/19688175/nsurlsessionconfiguration-timeoutintervalforrequest-vs-nsurlsession-timeoutinter

@cswelin Are you saying that whatever you're setting on URLSessionConfiguration is ignored? The timeout wouldn't be visible on and individual URLRequest before you hand it off to the session since it is manually instantiated, but I believe the timeout number should still be respected with a manually instantiated request which you have not changed any of the default values on.

@cswelin Are you saying that whatever you're setting on URLSessionConfiguration is ignored? The timeout wouldn't be visible on and individual URLRequest before you hand it off to the session since it is manually instantiated, but I _believe_ the timeout number should still be respected with a manually instantiated request which you have not changed any of the default values on.

Correct, when setting Charles to delay round response and have a 10 second timeout wouldn鈥檛 actually timeout after 10.

@cswelin Can you please open a new issue on this? If you have some time a sample project would also be super-helpful.

Was this page helpful?
0 / 5 - 0 ratings