I am writing a client for the leisure API using the aka http library. The library seems very powerful, but for me it is very unstable. Quite often (not always) this raises the following exception when I try to use HttpResponse.entity:
EntityStreamException: Truncating a stream of objects
and then stops processing subsequent requests. Maybe he is trying to cope with some kind of back pressure or the actors are just dying, I donโt know.
It doesnโt matter how I submit the request using the client level 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 client-level connection-level 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 }
This does not mean that I am using an object using unmarshaller or manually using getDataBytes, the result is the same - the above exception.
The response HTTP status is 200 OK, the headers are fine, this is the default object (so, without fragmentation), the content length is about 500-2000 Kb (increasing akka.http.parsing.max-content -length does not help, although the value default should be sufficient). The server is also in order - other http libraries on other platforms work with this API just fine.
Is this a mistake, or am I doing something wrong? What is the best non-blocking, asynchronous http library for scala?