ktorio / ktor

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

io.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline in iOS #866

Closed ImanX closed 5 years ago

ImanX commented 5 years ago

Ktor Version

1.1.1

cio

iOS, Multiplatform

Feedback

I have many issue with ktor, I changed behavior my code but I still don't result and response in iOS

my code on common:


    private val client = HttpClient()
    fun about(callback: (String) -> Unit) {
        GlobalScope.apply {
            launch(ApplicationDispatcher) {
                val result: String = client.get {
                    url("https://google.com")
                }

                callback(result)
            }
        }

    }

and my code on Android that It's work:


        APIPresentation().about {
            try {

                print(it)
            } catch (e: Exception) {
                e.printStackTrace();
            }

        }

and my Code on iOS that not response and print exception:

io.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline
 let presenetation = APIPresentation();
        presenetation.about { (s) -> KotlinUnit in
            print(s);

            return KotlinUnit();
        }

Where is problem?

e5l commented 5 years ago

Hi @ImanX, thanks for the report. Could you provide the stacktrace and cause?

ImanX commented 5 years ago

Hi @e5l , No because xcode only print log that.

icarumbas commented 5 years ago

Hey @ImanX and what does it print?

ImanX commented 5 years ago

@icarumbas in xcode log just print io.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline

icarumbas commented 5 years ago

I've got the same error with alike code, and i've noticed that it works with some other sites, for example
"https://stackoverflow.com". I'm not web developer, and i don't know what is difference between google and other sites, but this may help, i think.

talon commented 5 years ago
io.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline
        at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:61)
        at io.ktor.client.call.HttpClientCall$receive$1.invokeSuspend(HttpClientCall.kt)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
        at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:211)
        at io.ktor.util.pipeline.SuspendFunctionGun.access$resumeRootWith(PipelineContext.kt:63)
        at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:114)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:45)
        at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:285)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: kotlinx.coroutines.JobCancellationException: Job was cancelled

I get this after packaging a Ktor API with distZip, running the binary on a raspberry pi, and trying to fetch an endpoint that makes an http client request. Running locally works. Thought maybe the stack trace would help

(UPDATE: my issue was a timeout error cause it was so slowwww on the Pi)

e5l commented 5 years ago

For the url("https://google.com") I've got: Cause: kotlin.IllegalArgumentException: Charset ISO-8859-1 is not supported

It looks like we should find the way to decode ISO-8859-1 in kx.io.

GiuseppeGiacoppo commented 5 years ago

This problem is very similar to #787

AbdulMueed143 commented 5 years ago

Hi, I was trying to follow this below give Kotlin example for Multiplatform: https://medium.com/@aldychris/kotlin-multiplatform-for-ios-and-android-mobile-application-96a753e175f7

I have successfully run it but now I am getting error. Fail to run receive pipeline, after searching a lot and trying to find original exception it seems like it is illegalStateException:

molikuner commented 5 years ago

Hey, I got this problem at the JVM.

I use CIO as my engine on version 1.1.2 and my simple program is JVM based. Essentially, my code looks like this:

fun main() {
    runBlocking {
        val client = HttpClient(CIO)
        val response = CommonAPI.client.get<String> {
            url {
                protocol = URLProtocol.HTTPS
                host = "playlisten.rbb-online.de"
                encodedPath = "/radioberlin/main/index.php"
            }
        }
        println("'$response'")
        client.close()
    }
}

I get the stack:

Exception in thread "main" io.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline
    at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:61)
    at io.ktor.client.call.HttpClientCall$receive$1.invokeSuspend(HttpClientCall.kt)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
    at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:211)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:186)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
    at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:157)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:23)
    at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:55)
    at com.molikuner.spotify.MainKt$main$1.invokeSuspend(Main.kt:115)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
    at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:211)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:168)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:118)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:45)
    at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:211)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:168)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:118)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:45)
    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.kt:116)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:76)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:53)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:35)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
    at com.molikuner.spotify.MainKt.main(Main.kt:21)
Caused by: kotlinx.io.charsets.MalformedInputException: Input length = 1
    at kotlinx.io.charsets.CharsetJVMKt.throwExceptionWrapped(CharsetJVM.kt:287)
    at kotlinx.io.charsets.CharsetJVMKt.decode(CharsetJVM.kt:166)
    at kotlinx.io.charsets.EncodingKt.decode(Encoding.kt:104)
    at kotlinx.io.core.StringsKt.readText(Strings.kt:339)
    at kotlinx.io.core.StringsKt.readText$default(Strings.kt:338)
    at io.ktor.client.response.HttpResponseKt.readText(HttpResponse.kt:77)
    at io.ktor.client.features.HttpPlainText.read$ktor_client_core(HttpPlainText.kt:23)
    at io.ktor.client.features.HttpPlainText$Feature$install$2.invokeSuspend(HttpPlainText.kt:48)
    at io.ktor.client.features.HttpPlainText$Feature$install$2.invoke(HttpPlainText.kt)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
    ... 25 more

I know that the title indicates iOS, but it's pretty similar and the same code works for different websites as described above.

EDIT: changed version

e5l commented 5 years ago

Hi @molikuner, thanks for the report. Could you file the separate issue for that case?

cy6erGn0m commented 5 years ago

Fixed in 1.1.3.

ashokkateshiya commented 5 years ago

Hi, I was trying to follow this below give Kotlin example for Multiplatform: https://medium.com/@aldychris/kotlin-multiplatform-for-ios-and-android-mobile-application-96a753e175f7

I have successfully run it but now I am getting error. Fail to run receive pipeline, after searching a lot and trying to find original exception it seems like it is illegalStateException:

Hi Are you able to receive response?