Ktor: Getting a JobCancellationException on timeout or server not reachable

Created on 29 Jan 2020  路  4Comments  路  Source: ktorio/ktor

version 1.3.0, client: apache

If a POST request is cancelled due to a timeout or server not reachable, a JobCancellationException is thrown. But it contains no information about the problem/cause.

Steps to reproduce the behavior:

  1. Call an unreachable Service from within a runBlocking block.
  2. JobCancellationException is thrown with message Job was cancelled, and stack trace having length 0.

Expected behavior
Meaningful exception which describes the actual network problem, and contains a non-empty stack trace.

bug

Most helpful comment

Looks like it was fixed in 1.3.2. The test suggested by @dtretyakov now passes using Ktor 1.3.2 and Kotlin 1.3.60

All 4 comments

In 1.3.1 instead of actual exception CancellationException is thrown, but anyway it breaks existing code. The following test fails in 1.3.0/1.3.1:

    @Test
    fun `test ktor connect exception`() {
        assertFailsWith(ConnectException::class) {
            HttpClient(Apache).use { httpClient ->
                runBlocking {
                    httpClient.get<HttpResponse>("http://localhost:1234")
                }
            }
        }
    }

Would adding CancellationException to our list of retryable exceptions be a reasonable workaround until 1.3.2?

Looks like it was fixed in 1.3.2. The test suggested by @dtretyakov now passes using Ktor 1.3.2 and Kotlin 1.3.60

Sorry for the delay. Yep, the problem was fixed with the timeout feature release.
Closed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanf picture seanf  路  3Comments

dedward3 picture dedward3  路  4Comments

diaodou picture diaodou  路  3Comments

PPACI picture PPACI  路  4Comments

ManifoldFR picture ManifoldFR  路  4Comments