# Apollo crash when request is taking a long time

**URL:** <https://community.apollographql.com/t/apollo-crash-when-request-is-taking-a-long-time/5654>\
**Category:** Client SDKs\
**Tags:** kotlin\
**Created:** [February 7, 2023, 12:22am UTC](https://community.apollographql.com/t/apollo-crash-when-request-is-taking-a-long-time/5654 "2023-02-07T00:22:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chungwong](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/chungwong/32/3835_2.png) [@chungwong](https://community.apollographql.com/u/chungwong)\
**Post date:** [February 7, 2023, 12:22am UTC](https://community.apollographql.com/t/apollo-crash-when-request-is-taking-a-long-time/5654/1 "2023-02-07T00:22:19Z")

</div>

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?

```kotlin
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)

```

---

<div class="post-metadata">

**Author:** ![Benoit\_Lubek](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/benoit_lubek/32/2070_2.png) [@Benoit\_Lubek](https://community.apollographql.com/u/Benoit_Lubek)\
**Post date:** [February 7, 2023, 11:30am UTC](https://community.apollographql.com/t/apollo-crash-when-request-is-taking-a-long-time/5654/2 "2023-02-07T11:30:43Z")

</div>

Hi! 👋

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](https://www.apollographql.com/docs/kotlin/essentials/errors).

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

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

```

---

<div class="post-metadata">

**Author:** ![chungwong](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/chungwong/32/3835_2.png) [@chungwong](https://community.apollographql.com/u/chungwong)\
**Post date:** [February 7, 2023, 11:44pm UTC](https://community.apollographql.com/t/apollo-crash-when-request-is-taking-a-long-time/5654/3 "2023-02-07T23:44:11Z")

</div>

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