aallam / openai-kotlin

OpenAI API client for Kotlin with multiplatform and coroutines capabilities.
MIT License
1.5k stars 180 forks source link

EOF reached whilst reading during streaming #177

Open mikehearn opened 1 year ago

mikehearn commented 1 year ago

Description

Using the chatCompletions API I observed the following exception:

com.aallam.openai.api.exception.OpenAIHttpException: chunked transfer encoding, state: READING_LENGTH
    at com.aallam.openai.client.internal.http.HttpTransport.handleException(HttpTransport.kt:46)
    at com.aallam.openai.client.internal.http.HttpTransport.perform(HttpTransport.kt:36)
    at com.aallam.openai.client.internal.http.HttpTransport$perform$2.invokeSuspend(HttpTransport.kt)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
    at hydraulic.rendai.OpenAI.next(OpenAI.kt:60)
    at hydraulic.rendai.RendaiEngine.fixFiles(RendaiEngine.kt:29)
    at hydraulic.rendai.Rendai.go(Rendai.kt:69)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at picocli.CommandLine.executeUserObject(CommandLine.java:2056)
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2451)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2443)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2405)
    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2263)
    at picocli.CommandLine$RunLast.execute(CommandLine.java:2407)
    at hydraulic.app.impl.AppFrameworkInstance.execute(AppFrameworkInstance.kt:111)
    at picocli.CommandLine.execute(CommandLine.java:2160)
    at hydraulic.app.impl.AppFrameworkRuntime.init(AppFrameworkRuntime.kt:60)
    at hydraulic.rendai.RendaiApplication.main(RendaiApplication.java:50)
  Caused by: java.io.IOException: chunked transfer encoding, state: READING_LENGTH
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
  Caused by: java.io.EOFException: EOF reached while reading
    ... 3 more

I guess it's possible the other side just hung up, but I figure I'd put it here in case there's some deeper problem being revealed.

aallam commented 1 year ago

Hi @mikehearn, yes it most likely that the connection dropped, could you share which HTTP client did you use ? thanks!

mikehearn commented 1 year ago

ktor-client-java-jvm

zoltish commented 1 year ago

Did you ever find out what was causing this? Im currently looking into an EOF exception similar to this (although not using streaming); using CIO (also tested with java engine).

mikehearn commented 1 year ago

It didn't seem to reoccur.

zoltish commented 1 year ago

Maybe this can help someone else in the future save hours/days of debugging. My issue was related to using a different ktor version than what the library is using.