zio-http
zio-http copied to clipboard
Http client connection leak
Describe the bug When using the http client a lot, resources are eventually exhausted. A new connection is established on every client request and they are not closed. It doesn't matter if client is reused or not. This is tested on 2.0.0-RC11
To Reproduce Run this code and check connections with ss as explained in the output.
package test
import zhttp.service.server.ServerChannelFactory
import zhttp.service.{ChannelFactory, Client, EventLoopGroup, Server}
import zio._
import zio.test.TestAspect.withLiveClock
import zio.test._
object HttpTest extends ZIOSpecDefault {
def spec = test("Http client test") {
ZIO.scoped {
for {
_ <- Server.port(12345).make.orDie
client <- Client.make[Any]
_ <- client.request("http://localhost:12345")
_ <- client.request("http://localhost:12345")
_ <- client.request("http://localhost:12345")
_ <- client.request("http://localhost:12345")
_ <- client.request("http://localhost:12345")
_ <- client.request("http://localhost:12345")
_ <- ZIO.debug("When test is now hanging, run the following code (on Linux) and see that there are 6 connections open")
_ <- ZIO.debug("ss -o state established '( sport = :12345 )'")
_ <- ZIO.never
} yield assertTrue(1 == 1)
}
}.provideShared(EventLoopGroup.auto(), ChannelFactory.auto, ServerChannelFactory.auto) @@ withLiveClock
}
Hopefully already fixed with @vigoo's rewrite. 👍