Hey all, I’ve setup my Ktor client with both HttpT...
# ktor
j
Hey all, I’ve setup my Ktor client with both HttpTimeout and HttpRequestRetry plugins. Currently I’m facing an issue when using
retryOnExceptionIf
where I get a
CancellationException
instead of a
HttpRequestTimeoutException
when a timeout happens. This is preventing me from retrying timed out requests and using
retryOnException(… retryOnTimeout = true)
doesn’t seem to work either. There seems to be mention of this already here, but I can’t find a solution. Is this a known issue?
a
Can you please share a code snippet to reproduce it?
j
thanks for the reply, I was trying to create a snippet so I modified the Client Retry sample but I can see the issue is not reproducible there, the
retryOnExceptionIf
does get a
HttpRequestTimeoutException
. It’s worth noting that the
cause
property of the
CancellationException
I get is of type
HttpRequestTimeoutException
, does that hint something? also I’m using Charles proxy in my project to simulate the timeout
a
No. That's expected:
Copy code
val killer = scope.launch {
    delay(requestTimeout)
    val cause = HttpRequestTimeoutException(request)
    LOGGER.trace("Request timeout: ${request.url}")
    executionContext.cancel(cause.message!!, cause)
}
j
I see, I still can’t wrap my head around why this happens though, what determines if the exception will be a
HttpRequestTimeoutException
or a
CancellationException
?
a
It's difficult to say without the code