Helidon WebClient opens 1 connection per request

58 views Asked by At

Edit: this seems to be a bug in WebClient, see https://github.com/helidon-io/helidon/issues/8077

I am having an issue when stress testing my server using WebClient (using Scala):

  val client = WebClient
    .builder()
    .baseUri(s"http://localhost:8081")
    .build()

Then I have a single thread doing 1 mil requests but it fails around 17k requests because each request opens a connection (isn't that slow to open 1 connection per request?) with a java.net.BindException: Can't assign requested address. It reaches the maximum limit of connections (on my macos).

I am closing the HttpClientResponse object after each entity is processed:

    val r = client.post(uri).submit(data)
    try
      val e = r.entity()
      e.as(arrayOfBytes)
    finally r.close()

But running netstat after the exception I get 17k of these:

tcp4       0      0  127.0.0.1.61688        127.0.0.1.8081         TIME_WAIT  
tcp4       0      0  127.0.0.1.61689        127.0.0.1.8081         TIME_WAIT  
...

My assumption is that webclient closes the connection but due to the actual OS TCP connection staying open a bit more, I get the error. But nevertheless the client should be pooling connections which would be a lot more efficient.

Am I doing something wrong? Is there a way to configure WebClient reusing open connections or do I need to impl pooling myself?

0

There are 0 answers