Hi, we are using ktor-client-apache to fetch some...
# ktor
a
Hi, we are using ktor-client-apache to fetch some json:
Copy code
client.request(url) {
    HttpMethod.Get
    accept(ContentType.Application.Json)
    contentType(ContentType.Application.Json)
    timeout { requestTimeoutMillis = 60 * 1000
              connectTimeoutMillis = 5 * 1000
              socketTimeoutMillis = 60 * 1000 }
}
Using ktor 2.0.3 we never had any problems, with version 2.1.0 and 2.1.1 sometimes the call fails with:
Copy code
org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 41,606; received: 26,090)
Same code with the old ktor version started to work again correctly. Anyone having the same problem? Any hint on how to fix it? Thanks!
a
Could you please tell me to what endpoint a request should be made to reproduce
ConnectionClosedException
?
a
Hi @Aleksei Tirman [JB] unfortunately it’s a private endpoint. I’ll try with some other public api to see if I can reproduce it. Will let you know. Thanks!
r
I'm facing the same issue with current Ktor 2.3.8 with apache client.
Copy code
org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 12 689 932; received:
 8 388 160)
        at org.apache.http.impl.nio.codecs.LengthDelimitedDecoder.read(LengthDelimitedDecoder.java:89)
        at io.ktor.client.engine.apache.ApacheResponseConsumer$consumeContent$1.invoke(ApacheResponseConsumer.kt:54)
        at io.ktor.client.engine.apache.ApacheResponseConsumer$consumeContent$1.invoke(ApacheResponseConsumer.kt:53)
        at io.ktor.utils.io.ByteBufferChannel.writeAvailable(ByteBufferChannel.kt:1472)
        at io.ktor.utils.io.ByteWriteChannel$DefaultImpls.writeAvailable$default(ByteWriteChannel.kt:76)
        at io.ktor.client.engine.apache.ApacheResponseConsumer.consumeContent(ApacheResponseConsumer.kt:53)
        at org.apache.http.impl.nio.client.MainClientExec.consumeContent(MainClientExec.java:329)
        at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.consumeContent(DefaultClientExchangeHandlerImpl.java:1
5
It works ok for smaller responses but fails on one api call with larger response. The "recevied" sizes are different every time.
Could this be caused by some network problem?
a
We resolved the problem by switching the client from Apache to OkHttp
Copy code
private val client = HttpClient(OkHttp)
Don't know what was causing the problem though...
r
Thank you, I will probably try the same.
👍 1
s
What is the max limit of response Http client can return?
a
Do you mean the default timeout?
s
response pay load size when we request from any API?
a
Ktor doesn't impose constraints on the response payload size.
s
ho okay thanks for information