question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Operation is already in progress Exception

See original GitHub issue

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 ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Sahanovskyicommented, Jul 19, 2019

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

1reaction
q-litzlercommented, Jul 29, 2019

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Winforms Npgsql 3.0.5 "An operation already in progress ...
database - C# Winforms Npgsql 3.0. 5 "An operation already in progress" error when trying to run multiple commands inside same connection -...
Read more >
More detail on "Operation is already in progress" #1248 - GitHub
Then, if an "Operation is already in progress" is thrown, the exception could contain information about the ongoing operation.
Read more >
Admin Operation Already in Progress - Copado Documentation
"Unknown Exception - Admin operation already in progress." Steps to reproduce: 1. Navigate to an Org Credential record.
Read more >
apex - group membership operation already in progress
This error occurred: UNKNOWN_EXCEPTION: group membership operation already in progress. This is happening because the first step (assigning ...
Read more >
CloudPoint policy continuously fails with "Operation already in ...
Problem. CloudPoint policy continuously fails with "Operation already in progress on asset <asset_id>". Error Message.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found