Akka-HTTP: TcpIdleTimeoutException from singleRequest

Hi,

We are currently having some problems in our systems where we get TcpIdleTimeoutExceptions when calling singleRequest after we haven’t had to make any requests for a period longer than the idle-timeout. I believe the problem may be that we instantiate the HTTP Akka extention (HttpExt) only once and then re-use it for all requests. Is that a problem? If so, why and what is the proper way of handling this situation? Is the HTTP extensions really meant to be instantiated for every call to singleRequest?

Akka extension lifecycles are bound to the actor system, so calling SomeExtension(system) multiple times will return the same single instance given that you pass it the same system. In other words, if you only call it once and re-use that reference or multiple times should not matter at all (except for a slight overhead for looking the extension up that will likely not matter).

The extension uses a connection pool to share and limit connections to a given HTTP server, when using the request level or the host level client APIs there is a single connection pool per actor system managed by the extension.

Not sure why you are seeing the TcpIdleTimeoutExceptions, I think they can occur at two different levels, one is that the pool has a connection that has not been used for a while and should be closed. This should not bubble up as the returned future in singleRequest, the other one would be a single request that was started but never completed and no bytes were sent across the connection for a long while (for example because the request or response body was not consumed).