I'm writing a client for a rest API using the akka http library. The library seems very powerful, but it works very unstable for me. Quite often (not always) it throws the following exception when I try to consume an HttpResponse.entity:
EntityStreamException: Entity stream truncation
and after this it stops processing subsequent requests at all. Maybe it tries to deal with some back-pressure or actors just die, I don't know.
It doesn't matter how I send a request, using the Request-Level Client-Side API:
def pollSearchResult(searchId: String): FutureActionResult[String, SearchResult] = {
val request = HttpRequest(GET, s"http://***/Search/$searchId")
for {
response <- Http().singleRequest(request)
entity <- Unmarshal(response.entity).to[String]
result = entity.decodeEither[SearchResult]
} yield result
}
or using the Connection-Level Client-Side API:
val client = Http(actorSystem).outgoingConnection("***")
def pollSearchResult(searchId: String): FutureActionResult[String, SearchResult] = {
val request = HttpRequest(GET, s"Search/$searchId")
for {
response <- Source.single(request).via(client).runWith(Sink.head)
entity <- Unmarshal(response.entity).to[String]
result = entity.decodeEither[SearchResult]
} yield result
}
It doesn't metter whether I consume the entity using unmarshaller or manually using the getDataBytes, the result is the same - the above exception.
The http status of the response is 200 OK, headers are ok, it is a "Default" entity (so, no chunking), content length is about 500-2000 Kb (increasing akka.http.parsing.max-content-length doesn't help, although the default value should be enough). The server is also ok - other http libraries on other platforms work with this API just fine.
Is it a bug or I am doing something wrong? What is the best non blocking, asycnhonous http library for scala?