Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression - Netty Connection Exceptions with Large Connection Pool Count #2906

Closed
Not-Aru opened this issue Jun 13, 2024 · 4 comments · Fixed by #2907
Closed

Regression - Netty Connection Exceptions with Large Connection Pool Count #2906

Not-Aru opened this issue Jun 13, 2024 · 4 comments · Fixed by #2907
Labels
bug Something isn't working

Comments

@Not-Aru
Copy link

Not-Aru commented Jun 13, 2024

Using snapshot: 3.0.0-RC8+22-5ea81ef6-SNAPSHOT

There is a significant regression in request serving when using both ConnectionPoolConfig.Dynamic and ConnectionPoolConfig.Fixed. This seems to be a regression as this issue only appeared after migrating from RC6 to RC8. Exceptions include:

[info] Exception in thread "zio-fiber-823178100,1568885665" io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection reset by peer: /0.0.0.0:8080
[error] Jun 13, 2024 3:25:18 PM io.netty.channel.DefaultChannelPipeline onUnhandledInboundException Jun 13, 2024 3:25:18 PM io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
Exception in thread "zio-fiber-1756387034" io.netty.handler.codec.PrematureChannelClosureException: Channel closed while executing the request. This is likely caused due to a client connection misconfiguration

Reproducer:

package repro

import zio.{ Config => _, *}
import zio.http.*
import zio.http.ZClient.Config
import zio.http.netty.NettyConfig

object Reproducer extends ZIOAppDefault {
  private val clientLayer =
    (ZLayer.succeed(Config.default.copy(connectionPool = ConnectionPoolConfig.Dynamic(1, 512, 60.second))) ++ ZLayer
      .succeed(NettyConfig.defaultWithFastShutdown) ++
      DnsResolver.default) >>> Client.live

  private val url = URL.decode("http://0.0.0.0:8080/Test").toOption.get
  private val req = Request.post(url, Body.empty)

  private val routes =
    HttpApp(
      Routes(
        Method.POST / "Test" ->
          handler(ZIO.sleep(1.second).as(Response.text("success")))
      )
    )

  val run: ZIO[Any & ZIOAppArgs & Scope, Throwable, Unit] = {
    for {
      _ <- Server.serve(routes).fork
      client <- ZIO.service[Client]
      _ <- ZIO.foreachParDiscard(0 to 400) { _ =>
        ZIO
          .scoped[Any] {
            client.request(req).flatMap(_.body.asArray)
          }
          .repeatN(100)
      }
    } yield ()
  }.provide(clientLayer, Server.default)
}
@Not-Aru Not-Aru added the bug Something isn't working label Jun 13, 2024
@hearnadam
Copy link

This issue first appeared in RC7/RC8. We were not seeing this issue with RC6... @kyri-petrou

@kyri-petrou
Copy link
Collaborator

kyri-petrou commented Jun 13, 2024

I'll look into it. I think it might have been inadvertently caused by #2860 or #2861

EDIT: Those were merged in RC8, so if RC7 is affected as well that's a different issue

@kyri-petrou
Copy link
Collaborator

Regression introduced in #2843, looking into it hopefully I'll have a fix soon

@kyri-petrou
Copy link
Collaborator

@Not-Aru @hearnadam I know you're quite interested in the performance of the client, so just FYI re this PR: #2919.

It improves the performance of the client ~45% according to the benchmarks that I added there. Hopefully you'll be able to see that improvement as well in your benchmarks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants