Hello, I’m using ktor client (v1.6.8) and got this...
# ktor
a
Hello, I’m using ktor client (v1.6.8) and got this exception
java.io.EOFException: Failed to parse HTTP response: unexpected EOF
Can’t seem to understand further what happened but from my understanding it seems like it tried to parse the response payload but there wasn’t any.
Copy code
java.io.EOFException: Failed to parse HTTP response: unexpected EOF
	at io.ktor.client.engine.cio.UtilsKt.readResponse(utils.kt:116)
	at i.k.c.engine.cio.UtilsKt$readResponse$1.invokeSuspend(utils.kt)
	at k.c.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at k.c.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
	at k.c.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at k.c.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
	at k.c.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Seems like the channel was closed and parseResponse returned null
a
Could you please share a code snippet to reproduce your issue?
a
I have a CIO client with the JsonFeature and Logging installed and just making a GET request to an endpoint that returns some data. It looks like it was a problem in the middle and somehow it closed the connection and made ktor throw that error.
c
Bump. I think this is working as expected and BE response is the cause, but my question is, when we get he java.io.EOFException I see that ktor is retrying the request. How can this mechanism be disabled as there are no throwable produced, the failure of parsing just printed in the console. Or how can ktor be forced to throw a the error instead of silently log it? @Aleksei Tirman [JB]
At the time of printing the EOF exception there are no response logged from ktor, would this still be possible to catch in HttpResponseValidator / validateResponse block maybe?
a
Ktor doesn’t retry a request except when the
HttpRequestRetry
plugin is installed or the
OkHttp
engine is used. Can you share a code snippet to reproduce the retry on EOF exception?
c
Retry is installed so I guess this is expected and the desired behaviour in all cases except when EOF happens. So when EOF exception happens due to BE error I would like to ditch the retry and just throw the exception, but right now the EOF is just logged as normal message to the console. There is a validator installed, maybe I should add an other after this for the EOF exception?
Copy code
HttpResponseValidator {
    handleResponseExceptionWithRequest { cause, _ ->
        if (cause !is ResponseException) return@handleResponseExceptionWithRequest
        val exceptionResponse = cause.response
        when (exceptionResponse.status) {
...
...
a
Can you please file an issue about EOF exception being retried? Also, please attach a code snippet to reproduce it.
301 Views