ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
13.09k stars 1.07k forks source link

HTTTP Client Gzip failed with exception: kotlinx.coroutines.JobCancellationException: Parent job is Completed; #1837

Closed jittya closed 4 years ago

jittya commented 4 years ago

Ktor Version and Engine Used (client or server and name) 1.3.2, client(OkHttp), additional ktor modules included (client-core, client-logging, client-encoding)

Describe the bug When configuring ContentEncoding { gzip() } in Okhttp client http call is failing

failed with exception: kotlinx.coroutines.JobCancellationException: Parent job is Completed; job=JobImpl{Completed}@35cb342

To Reproduce Steps to reproduce the behavior:

  1. Write the following val client = HttpClient(OkHttp) {

    Logging {
        logger = Logger.SIMPLE
        level = LogLevel.ALL
    }
    ContentEncoding { gzip() }

    } GlobalScope.apply { launch(Dispatchers.Default) { val result: String = client.get { url(Url("http://148.151.131.221:7200/api/Mobility/GetAvailableRoles")) } println(result) client.close() } }

  2. Run as android app
  3. See error

2020-04-29 15:21:53.143 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: REQUEST: http://148.151.131.221:7200/api/Mobility/GetAvailableRoles 2020-04-29 15:21:53.143 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: METHOD: HttpMethod(value=GET) 2020-04-29 15:21:53.144 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: COMMON HEADERS 2020-04-29 15:21:53.145 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> Accept-Encoding: gzip 2020-04-29 15:21:53.146 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> Accept-Charset: UTF-8 2020-04-29 15:21:53.146 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> Accept: / 2020-04-29 15:21:53.146 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: CONTENT HEADERS 2020-04-29 15:21:53.148 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: BODY Content-Type: null 2020-04-29 15:21:53.255 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: BODY START 2020-04-29 15:21:53.255 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: 2020-04-29 15:21:53.255 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: BODY END 2020-04-29 15:21:54.377 21841-21884/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: BODY Content-Type: application/json; charset=utf-8 2020-04-29 15:21:54.377 21841-21884/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: BODY START 2020-04-29 15:21:54.459 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: RESPONSE: 200 OK 2020-04-29 15:21:54.460 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: METHOD: HttpMethod(value=GET) 2020-04-29 15:21:54.461 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: FROM: http://148.151.131.221:7200/api/Mobility/GetAvailableRoles 2020-04-29 15:21:54.463 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: COMMON HEADERS 2020-04-29 15:21:54.464 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> cache-control: no-cache 2020-04-29 15:21:54.464 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> content-encoding: gzip 2020-04-29 15:21:54.464 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> content-length: 1607 2020-04-29 15:21:54.465 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> content-type: application/json; charset=utf-8 2020-04-29 15:21:54.465 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> date: Wed, 29 Apr 2020 11:20:29 GMT 2020-04-29 15:21:54.465 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> expires: -1 2020-04-29 15:21:54.466 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> pragma: no-cache 2020-04-29 15:21:54.466 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> server: Microsoft-IIS/8.5 2020-04-29 15:21:54.466 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> vary: Accept-Encoding 2020-04-29 15:21:54.466 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> x-aspnet-version: 4.0.30319 2020-04-29 15:21:54.467 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: -> x-powered-by: ASP.NET 2020-04-29 15:21:54.476 21841-21882/org.jetbrains.kotlin.mpp_app_android I/System.out: HttpClient: RESPONSE http://148.151.131.221:7200/api/Mobility/GetAvailableRoles failed with exception: kotlinx.coroutines.JobCancellationException: Parent job is Completed; job=JobImpl{Completed}@35cb342

thatbroc commented 4 years ago

I have been able to repro this same behavior utilizing CIO and Apache engines as well.

jittya commented 4 years ago

setting level = LogLevel.ALL and BODY is the issue. as a workaround change LogLevel to other than ALL or BODY

thatbroc commented 4 years ago

This is still occurring when using from a JVM app with the Apache engine, even with the logging work around.

e5l commented 4 years ago

The ticket is a duplicate of https://github.com/ktorio/ktor/issues/1780

Closed