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

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

Closed
kobe2000 opened this issue Dec 21, 2018 · 10 comments
Closed
Assignees
Labels

Comments

@kobe2000
Copy link

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)
@e5l e5l added the bug label Dec 22, 2018
@e5l
Copy link
Member

e5l commented Dec 22, 2018

Hi @kobe2000, thanks for the report.
It's probably a bug in kotlinx.io.

@ScottPierce
Copy link

I'm seeing this bug in ktor client 1.1.3 on Android with OkHttp as the engine:

2019-03-14 12:53:57.109 2002-2002 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.rally.coach.internal.debug, PID: 2002
    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.readAsMuchAsPossible(ByteBufferChannel.kt:2573)
        at kotlinx.coroutines.io.ByteBufferChannel.readAsMuchAsPossible$default(ByteBufferChannel.kt:436)
        at kotlinx.coroutines.io.ByteBufferChannel.readRemaining(ByteBufferChannel.kt:2161)
        at kotlinx.coroutines.io.ByteReadChannelKt.readRemaining(ByteReadChannel.kt:175)
        at io.ktor.client.response.HttpResponseKt.readText(HttpResponse.kt:75)
        at io.ktor.client.response.HttpResponseKt.readText$default(HttpResponse.kt:74)
        at com.rally.coach.api.service.utils.ApiExceptionUtilKt.toApiException(ApiExceptionUtil.kt:18)
        at com.rally.coach.api.BaseApi.withApiContext(BaseApi.kt:46)
        at com.rally.coach.api.BaseApi$withApiContext$1.invokeSuspend(Unknown Source:32)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
        at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:285)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

@ScottPierce
Copy link

I posted this bug in kotlinx.io here: Kotlin/kotlinx-io#43

@cy6erGn0m
Copy link
Contributor

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

@kobevaliant
Copy link

Hi, I met this error again recently, here is the stacktrace. The ktor version is 1.1.3
1

@kobevaliant
Copy link

kobevaliant commented 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

@Romain-P
Copy link

For me, readUntilDelimiter(buffer: ByteBuffer); is working once, then the function becomes non blocking and always returns 0

@oleg-larshin
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

@e5l
Copy link
Member

e5l commented Apr 5, 2021

Fixed since 1.5.0

@e5l e5l closed this as completed Apr 5, 2021
@longqingzhao
Copy link

I have the same exception in version 1.6.2.
image
image

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

8 participants