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.

java.lang.IllegalStateException: Reading is not available in state Reading

See original GitHub issue

Ktor Version

1.0.1

Ktor Engine Used(client or server and name)

Netty / Firefox

JVM Version, Operating System and Relevant Context

1.8 Windows Server 2008R2

Feedback

I don’t how this happen, I can’t reproduce it.

stacktrace:

500 Internal Server Error: POST - /search/TT
java.lang.IllegalStateException: Reading is not available in state Reading
        at kotlinx.coroutines.io.internal.ReadWriteBufferState.startReading$kotlinx_coroutines_io_jvm(ReadWriteBufferSta
te.kt:19)
        at kotlinx.coroutines.io.ByteBufferChannel.setupStateForRead(ByteBufferChannel.kt:238)
        at kotlinx.coroutines.io.ByteBufferChannel.access$setupStateForRead(ByteBufferChannel.kt:21)
        at kotlinx.coroutines.io.ByteBufferChannel.lookAhead(ByteBufferChannel.kt:2868)
        at kotlinx.coroutines.io.DelimitedKt.readUntilDelimiter(Delimited.kt:24)
        at io.ktor.http.cio.MultipartKt.copyUntilBoundary(Multipart.kt:339)
        at io.ktor.http.cio.MultipartKt$copyUntilBoundary$1.invokeSuspend(Multipart.kt)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
        at kotlinx.coroutines.DispatchedContinuation.resumeWith(Dispatched.kt:111)
        at kotlinx.coroutines.io.internal.CancellableReusableContinuation.resumeWith(CancellableReusableContinuation.kt:
83)
        at kotlinx.coroutines.io.ByteBufferChannel.resumeWriteOp(ByteBufferChannel.kt:2207)
        at kotlinx.coroutines.io.ByteBufferChannel.bytesRead(ByteBufferChannel.kt:865)
        at kotlinx.coroutines.io.ByteBufferChannel.readAsMuchAsPossible(ByteBufferChannel.kt:426)
        at kotlinx.coroutines.io.ByteBufferChannel.readAvailable(ByteBufferChannel.kt:559)
        at kotlinx.coroutines.io.ByteBufferChannel.readAvailableSuspend(ByteBufferChannel.kt:593)
        at kotlinx.coroutines.io.ByteBufferChannel$readAvailableSuspend$2.invokeSuspend(ByteBufferChannel.kt)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
        at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:236)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:748)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kobevaliantcommented, Jul 5, 2019

Hi, I upgraded ktor to 1.2.2. But this issue exists still. The client is commons-httpclient. The server OS is CentOS7. After this exeption happens, all clients will be blocked forever(without timeout settings). Stacktrace is:

java.lang.IllegalStateException: Reading is not available in state Reading
  at kotlinx.coroutines.io.internal.ReadWriteBufferState.startReading$kotlinx_coroutines_io(ReadWriteBufferState.kt:19)
  at kotlinx.coroutines.io.ByteBufferChannel.setupStateForRead(ByteBufferChannel.kt:238)
  at kotlinx.coroutines.io.ByteBufferChannel.access$setupStateForRead(ByteBufferChannel.kt:21)
  at kotlinx.coroutines.io.ByteBufferChannel.lookAhead(ByteBufferChannel.kt:2874)
  at kotlinx.coroutines.io.DelimitedKt.readUntilDelimiter(Delimited.kt:24)
  at io.ktor.http.cio.MultipartKt.copyUntilBoundary(Multipart.kt:346)
  at io.ktor.http.cio.MultipartKt$copyUntilBoundary$1.invokeSuspend(Multipart.kt)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
  at kotlinx.coroutines.DispatchedContinuation.resumeWith(Dispatched.kt:108)
  at kotlinx.coroutines.io.internal.CancellableReusableContinuation.resumeWith(CancellableReusableContinuation.kt:83)
  at kotlinx.coroutines.io.ByteBufferChannel.resumeWriteOp(ByteBufferChannel.kt:2210)
  at kotlinx.coroutines.io.ByteBufferChannel.bytesRead(ByteBufferChannel.kt:865)
  at kotlinx.coroutines.io.ByteBufferChannel.readAsMuchAsPossible(ByteBufferChannel.kt:426)
  at kotlinx.coroutines.io.ByteBufferChannel.readAvailable(ByteBufferChannel.kt:559)
  at kotlinx.coroutines.io.ByteBufferChannel.readAvailableSuspend(ByteBufferChannel.kt:593)
  at kotlinx.coroutines.io.ByteBufferChannel$readAvailableSuspend$2.invokeSuspend(ByteBufferChannel.kt)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
  at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
  at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
  at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
  at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
  at java.lang.Thread.run(Thread.java:748)

@cy6erGn0m Please take a look, thanks

1reaction
cy6erGn0mcommented, Mar 21, 2019

@e5l same here: according to the stacktrace

        at kotlinx.coroutines.io.ByteBufferChannel.lookAhead(ByteBufferChannel.kt:2868)
        at kotlinx.coroutines.io.DelimitedKt.readUntilDelimiter(Delimited.kt:24)

readUntilDelimiter does enter lookAhead and fails immediately because we already have reading state. I see no way how any read operation could leave reading state unreleased without exceptions that usually kill everything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.IllegalStateException when using State in Android ...
I have ViewModel with Kotlin sealed class to provide different states for UI. Also, I use androidx ...
Read more >
How to Fix The IllegalStateException in Java - Rollbar
The IllegalStateException is thrown when the Java environment or application is not in an appropriate state for the requested operation.
Read more >
How to Solve java.lang.IllegalStateException in Java main ...
IllegalStateException in Java main Thread we must ensure that any method in our code cannot be called at an illegal or an inappropriate...
Read more >
java.lang.IllegalStateException: Reading a state that was ...
java.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied.
Read more >
IllegalStateException when writing in coroutine context ...
Exception in thread "DefaultDispatcher-worker-1" java.lang.IllegalStateException: Writing is not available in state Writing at ...
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