Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation is already in progress Exception #1216

Closed
q-litzler opened this issue Jul 2, 2019 · 5 comments
Closed

Operation is already in progress Exception #1216

q-litzler opened this issue Jul 2, 2019 · 5 comments
Assignees
Labels

Comments

@q-litzler
Copy link

q-litzler commented Jul 2, 2019

Ktor Version

1.2.2

Ktor Engine Used(client or server and name)

Client Android

JVM Version, Operating System and Relevant Context

1.8, reproductible on a pure JVM project, and on a Android application consuming this JVM project.

Feedback

Stacktrace:

Exception in thread "Thread-3 @ktor-android-context#4" 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.discardSuspend(ByteBufferChannel.kt:1723)
	at kotlinx.coroutines.io.ByteBufferChannel.discard(ByteBufferChannel.kt:1707)
	at kotlinx.coroutines.io.ByteReadChannelKt.discard(ByteReadChannel.kt:203)
	at io.ktor.client.response.HttpResponse$close$1.invokeSuspend(HttpResponse.kt:71)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

How to reproduce:

runBlocking {
            val client = HttpClient(Android) {
                install(JsonFeature) {
                    serializer = KotlinxSerializer()
                        .also {
                            it.register(JsonArraySerializer)
                        }
                }
            }

            repeat(100) {
                try {
                    withTimeout(500) {
                        client.request<JsonArray>("https://jsonplaceholder.typicode.com/todos/") {

                        }
                    }
                } catch (exception: TimeoutCancellationException) {
                    println(exception.message)
                }
            }
        }

From what I understand, it seems like if the timeout cancellation happens during the json deserialisation phase of the request, we get the Operation is already in progress exception. Because of that, it is not easy to reproduce: You might have to tweak the timeout value of 500, or run the test multiple times, for the exception to appear.

Is there a workaround in the meantime ?

@e5l e5l self-assigned this Jul 2, 2019
@e5l e5l added the bug label Jul 2, 2019
@Sahanovskyi
Copy link

Sahanovskyi commented Jul 19, 2019

@e5l when is it supposed to be fixed? Or maybe there is some way to temporary work around the issue?

@q-litzler
Copy link
Author

Seems like 1.2.3-rc fixes this. I can no longer reproduce, but can you tell us if that is indeed the case ? Thank you 🙏

@JanStoltman
Copy link

@q-litzler In the release notes for 1.2.3-rc there is "Fixed client response body cancellation" so I would guess that's about this issue

@q-litzler
Copy link
Author

@q-litzler In the release notes for 1.2.3-rc there is "Fixed client response body cancellation" so I would guess that's about this issue

Yes indeed, I also found this commit which looks related. Just making sure :)

@e5l
Copy link
Member

e5l commented Jul 30, 2019

Yep, sorry for the delay. Closed

@e5l e5l closed this as completed Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants