Akka HTTP Connection Pool Hangs After Couple of Hours

不羁的心 提交于 2019-12-06 00:02:22

You are not consuming the entity of the responses you get back from the server. Citing the docs below:

Consuming (or discarding) the Entity of a request is mandatory! If accidentally left neither consumed or discarded Akka HTTP will assume the incoming data should remain back-pressured, and will stall the incoming data via TCP back-pressure mechanisms. A client should consume the Entity regardless of the status of the HttpResponse.

The entity comes in the form of a Source[ByteString, _] which needs to be run to avoid resource starvation.

If you don't need to read the entity, the simplest way to consume the entity bytes is to discard them, by using

res.discardEntityBytes()

(you can attach a callback by adding - e.g. - .future().map(...)).

This page in the docs describes all the alternatives to this, including how to read the bytes if needed.

--- EDIT

After more code/info was provided, it is clear that the resource consumption is not the problem. There is another big red flag in this implementation, namely the Thread.sleep in the retry method. This is a blocking call that is very likely to starve the threading infrastructure of your underlying actor system.

A full blown explanation of why this is dangerous was provided in the docs.

Try changing that and using akka.pattern.after (docs). Example below:

def retry = akka.pattern.after(200 millis, using = system.scheduler)(request(uri))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!