https://kotlinlang.org logo
Title
a

Anton Afanasev

04/13/2022, 4:55 PM
Hi. Trying to set timeout on KMM, For test purposes set a pretty small value and expect to receive a timeout exception. On Android I am capable to receive an error, but on iOS my request execute as usual. What am I missing?
internal fun defaultHttpClient(): HttpClient = HttpClient {
    install(HttpTimeout) {
        connectTimeoutMillis = 10
        requestTimeoutMillis = 10
    }
}
ktor 1.6.4
a

Aleksei Tirman [JB]

04/13/2022, 5:00 PM
Seems like only the
socketTimeoutMillis
timeout works for the
ios
engine.
a

Anton Afanasev

04/13/2022, 5:02 PM
As far as I understand there are no support for WS on ktor 1.6.4
a

Aleksei Tirman [JB]

04/13/2022, 5:03 PM
For iOS no. Only since the 2.0.0 version.
a

Anton Afanasev

04/13/2022, 5:05 PM
So, is
socketTimeoutMillis
related to the iOS REST or WS?
BTW, WS was released 2 days ago, no?
a

Aleksei Tirman [JB]

04/13/2022, 5:07 PM
So, is
socketTimeoutMillis
related to the iOS REST or WS?
It’s related to both.
BTW, WS was released 2 days ago, no?
The version 2.0.0 of Ktor was released a few days ago.
🎉 1
a

Anton Afanasev

04/13/2022, 5:09 PM
Thanks. Now, I got it.
@Aleksei Tirman [JB] Still trying to understand what would be the best approach to set timeout values that will work same way for both Android and iOS. As you mentioned before, ios engine respects only
socketTimeout
. Would it be correct to share this value for both platforms? I played around with numbers and seems like Android respects the
requestTimeoutMillis
more than
socketTimeout
. For instance setting
install(HttpTimeout) {
        socketTimeoutMillis = 10
        requestTimeoutMillis = 100
    }
will fail with: io.ktor.client.features.HttpRequestTimeoutException: Request timeout has expired [url=http://myurl, request_timeout=100 ms] even that socketTimeoutMillis has lower value. Thats a little bit confusing, why...