# Why do I get a TimeoutCancellationException?

**URL:** https://discuss.kotlinlang.org/t/why-do-i-get-a-timeoutcancellationexception/17419
**Category:** Support
**Created:** [April 30, 2020, 5:49am UTC](https://discuss.kotlinlang.org/t/why-do-i-get-a-timeoutcancellationexception/17419 "2020-04-30T05:49:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jeffgnpc](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jeffgnpc/32/2523_2.png) [@jeffgnpc](https://discuss.kotlinlang.org/u/jeffgnpc)
#### Post date: [April 30, 2020, 5:49am UTC](https://discuss.kotlinlang.org/t/why-do-i-get-a-timeoutcancellationexception/17419/1 "2020-04-30T05:49:12Z")

</div>

I have a chunk of code that makes HTTP calls using Ktor HttpClient. This code has a loop that will try these requests multiple times if there are failures. Usually few times a day I get exceptions like this:

```
kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 15000 ms
at kotlinx.coroutines.TimeoutKt.TimeoutCancellationException(Timeout.kt:116)
at kotlinx.coroutines.TimeoutCoroutine.run(Timeout.kt:86)
at kotlinx.coroutines.EventLoopImplBase$DelayedRunnableTask.run(EventLoop.common.kt:492)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:271)
at kotlinx.coroutines.DefaultExecutor.run(DefaultExecutor.kt:68)
at java.base/java.lang.Thread.run(Thread.java:834)

```

I did some google searches and found that `TimeoutCancellationException` get thrown from `withTimeout()`methods ([https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html](https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html)), but I’m not making these calls.

Is there anyway to understand what code defines these timeout parameters?

This is running in a server side JVM using Kotlin 1.3.70 and Ktor 1.3.1.

---

<div class="post-metadata">

### Author: ![gtcno](https://avatars.discourse-cdn.com/v4/letter/g/bc79bd/32.png) [@gtcno](https://discuss.kotlinlang.org/u/gtcno)
#### Post date: [June 25, 2020, 10:32am UTC](https://discuss.kotlinlang.org/t/why-do-i-get-a-timeoutcancellationexception/17419/2 "2020-06-25T10:32:07Z")

</div>

This is the default for the CIO client. You can set the timeout in the config block

HttpClient(CIO.create{  
requestTimeout = 15000 //ms. 0 to disable  
})

---

<div class="post-metadata">

### Author: ![jeffgnpc](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jeffgnpc/32/2523_2.png) [@jeffgnpc](https://discuss.kotlinlang.org/u/jeffgnpc)
#### Post date: [June 25, 2020, 5:53pm UTC](https://discuss.kotlinlang.org/t/why-do-i-get-a-timeoutcancellationexception/17419/3 "2020-06-25T17:53:14Z")

</div>

Thanks so much for the reply gtcno.

How did you know that it was CIO? Is there anyway to actually track this down encase it happens with another library?
