K
Kord17mo ago
tmpod

Change timeout threshold for requests

I'm trying to do some big attachment uploads to Discord (like, around the 100MiB Nitro boosted limit), and sometimes the message create requests just timeout with:
io.ktor.client.plugins.HttpRequestTimeoutException: Request timeout has expired [url=https://discord.com/api/v10/channels/.../messages, request_timeout=unknown ms]
at io.ktor.client.engine.cio.EndpointKt$setupTimeout$timeoutJob$1.invokeSuspend(Endpoint.kt:307)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
io.ktor.client.plugins.HttpRequestTimeoutException: Request timeout has expired [url=https://discord.com/api/v10/channels/.../messages, request_timeout=unknown ms]
at io.ktor.client.engine.cio.EndpointKt$setupTimeout$timeoutJob$1.invokeSuspend(Endpoint.kt:307)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Is this hitting a timeout configured on Ktor or is it a Discord limit?
If it's the former (and looking at the stack trace, it looks like it), how can I change it? I assume by tweaking some options in HttpClient's constructor and passing that custom client to Kord? Thanks! :3
2 Replies
SchlaubiBus
SchlaubiBus17mo ago
What is your code for downloading it, also you can change timeouts with the HttpTimeout ktor plugin
tmpod
tmpodOP17mo ago
it's complicated, but I essentially use #bodyAsChannel() and then read chunks using #readAvailable(ByteArray) the timeout is on the upload though I will check out that plugin Forgot to say, this worked! I used install(HttpTimeout) on the HttpClient builder and in it set requestTimeoutMillis to a fitting amount

Did you find this page helpful?