GET request as a ByteReadChannel causes crash in Ktor 1.2.0 on Android
See original GitHub issueKtor Version
1.2.0 (Version 1.2.0-alpha-1.3.0-eap-125
works fine, error started after version 1.2.0-rc
)
Ktor Engine Used(client or server and name)
OkHttp on Android
JVM Version, Operating System and Relevant Context
Android 9 (did not test on other versions)
Feedback
After updating to Ktor 1.2.0
I keep getting the following error:
2019-05-16 17:58:08.402 30329-30329/com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 30329
java.lang.IllegalStateException: Operation is already in progress
at kotlinx.coroutines.io.ByteBufferChannel.suspensionForSize(ByteBufferChannel.kt:2984)
at kotlinx.coroutines.io.ByteBufferChannel.access$suspensionForSize(ByteBufferChannel.kt:21)
at kotlinx.coroutines.io.ByteBufferChannel.readSuspendImpl(ByteBufferChannel.kt:2309)
at kotlinx.coroutines.io.ByteBufferChannel.readSuspend(ByteBufferChannel.kt:2249)
at kotlinx.coroutines.io.ByteBufferChannel.readAvailableSuspend(ByteBufferChannel.kt:587)
at kotlinx.coroutines.io.ByteBufferChannel.readAvailable(ByteBufferChannel.kt:555)
at kotlinx.coroutines.io.jvm.javaio.InputAdapter$loop$1.loop(Blocking.kt:31)
at kotlinx.coroutines.io.jvm.javaio.InputAdapter$loop$1$loop$1.invokeSuspend(Unknown Source:11)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
at kotlinx.coroutines.io.jvm.javaio.UnsafeBlockingTrampoline.dispatch(Blocking.kt:276)
at kotlinx.coroutines.DispatchedContinuation.resumeWith(Dispatched.kt:104)
at kotlinx.coroutines.io.jvm.javaio.BlockingAdapter.submitAndAwait(Blocking.kt:213)
at kotlinx.coroutines.io.jvm.javaio.BlockingAdapter.submitAndAwait(Blocking.kt:186)
at kotlinx.coroutines.io.jvm.javaio.InputAdapter.read(Blocking.kt:55)
at okio.Okio$2.read(Okio.java:140)
at okio.RealBufferedSource.request(RealBufferedSource.java:72)
at com.squareup.moshi.JsonUtf8Reader.nextNonWhitespace(JsonUtf8Reader.java:996)
at com.squareup.moshi.JsonUtf8Reader.doPeek(JsonUtf8Reader.java:319)
at com.squareup.moshi.JsonUtf8Reader.peek(JsonUtf8Reader.java:193)
at (removed some lines of my code)
at com.myapp.MyClass$initialize$2.invokeSuspend(MyClass.kt:99)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:215)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:172)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:67)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:122)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:215)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:172)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:67)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:122)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:215)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:172)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:67)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:122)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:215)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:172)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:67)
at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:122)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
2019-05-16 17:58:08.402 30329-30329/com.myapp E/AndroidRuntime: at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7032)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
This is the code which causes the problem:
GlobalScope.launch {
val client = HttpClient(OkHttp)
val channel = client.get<ByteReadChannel> {
url("https://kotlinlang.org/")
}
channel.readRemaining()
}
Here is an Android sample project which reproduces the issue. Run the app and it will throw the exception.
(related discussion on Slack: https://kotlinlang.slack.com/archives/C0A974TJ9/p1558022742209800)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
WhatsNew 2.0 | Ktor Framework
iOS simulator crashes on an attempt to use the CIO engine for iOS application.
Read more >application crashes unexpectedly when making HTTP request
Android : application crashes unexpectedly when making HTTP request. Relates to 1. Relates to 1 issue (1 unresolved). KTOR-1219 Android: no logs are...
Read more >Change log for kotlinx.coroutines
When cancelled coroutine crashes due to some other exception, this other exception becomes the cancellation reason of the coroutine, while the original ...
Read more >https://raw.githubusercontent.com/ktorio/ktor/mast...
... Maven: ktor-server-test-host-jvm causes dependency error starting from Ktor 2.0.3 ... WebSocket client closes connection due to an HTTP request timeout ...
Read more >I get "kotlinx/coroutines/io/ByteReadChannel" when I try to ...
Moshi 1.0.1 relies on some outdated Ktor API. Consider either moving back to Ktor 1.3.2 or (better) use another JSON handler (there are ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @Thomas-Vos, thanks for the report. It’s a bug and will be fixed in next release.
Consider using
client.get<HttpResponse>
for now.uhm, I just noticed that the report from Crashlytics looks different from the one on the Google console. I’m not sure if they are the same issue. I’ll update to 1.2.3-rc and report back.