Apollo crash when request is taking a long time

If a request to an API endpoint is taking a long time to process, say 20 seconds, I found the kotlin client (3.7.3) will just crash the whole app.

Is it an expected behaviour?

com.apollographql.apollo3.exception.ApolloNetworkException: Failed to execute GraphQL http network request
    at com.apollographql.apollo3.network.http.DefaultHttpEngine.execute(OkHttpEngine.kt:82)
    at com.apollographql.apollo3.network.http.HttpNetworkTransport$EngineInterceptor.intercept(HttpNetworkTransport.kt:150)
    at com.apollographql.apollo3.network.http.DefaultHttpInterceptorChain.proceed(HttpInterceptor.kt:22)
    at com.apollographql.apollo3.network.http.LoggingInterceptor.intercept(LoggingInterceptor.kt:110)
    at com.apollographql.apollo3.network.http.DefaultHttpInterceptorChain.proceed(HttpInterceptor.kt:22)
    at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invokeSuspend(HttpNetworkTransport.kt:58)
    at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invoke(Unknown Source:8)
    at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invoke(Unknown Source:4)
    at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61)
    at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:230)
    at kotlinx.coroutines.flow.internal.ChannelFlowOperatorImpl.flowCollect(ChannelFlow.kt:195)
    at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo$suspendImpl(ChannelFlow.kt:157)
    at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo(Unknown Source:0)
    at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:60)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

Hi! :wave:

It is expected that network exceptions (including timeouts) are thrown from the client, and as such they should be handled with a try catch block on the application’s side.

More information about error handling is available here.

That being said, if you want to change the default timeout which is 1 minute, you can do so like this:

    apolloClient = ApolloClient.Builder()
        .httpEngine(DefaultHttpEngine(timeoutMillis = ...))
        .serverUrl(...)
        .build()

Thank you very much for your reply and confirmation. I will try the error handling approach as it is more resilient.