'How to make sure rector netty http client create fix connection to http server

I use bellow code to create reactor netty http client and use this client to send request.

ConnectionProvider connectionProvider = ConnectionProvider.builder("lead")
    .maxConnections(10)
    .pendingAcquireTimeout(Duration.ofSeconds(60))
    .pendingAcquireMaxCount(10)
    .maxLifeTime(Duration.ofSeconds(100))
    .maxIdleTime(Duration.ofSeconds(60))
    .build();

HttpClient httpClient = HttpClient.create(connectionProvider)
    .keepAlive(true);

I loop send request:

for (; ; ) {
    httpClient.get().uri("http://localhost:5230/test")
        .response()
        .subscribe();
}

I hope http client only create 10 connection to http server,but the result not as expected,client create many connection to http server(server listen on 5230 port)(this connection soon closed):

$ netstat -nap |grep "5230" output
  TCP    127.0.0.1:5230         0.0.0.0:0              LISTENING       1980
  TCP    127.0.0.1:5230         127.0.0.1:51012        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51014        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51015        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51016        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51017        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51018        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51019        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51020        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51021        ESTABLISHED     1980
  TCP    127.0.0.1:5230         127.0.0.1:51022        ESTABLISHED     1980
  TCP    127.0.0.1:50393        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50394        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50395        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50396        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50397        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50398        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50399        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50400        127.0.0.1:5230         TIME_WAIT       0
  TCP    127.0.0.1:50401        127.0.0.1:5230         TIME_WAIT       0
  .... there is many connection in TIME_WAIT status....

How can i make sure http client only create 10 connection to http server?

Version:

jdk 1.8.0_201
reactory-netty 1.0.3
netty 4.15.9.Final


Solution 1:[1]

With the help of Violeta Georgieva,in reactory netty response() method will case http client close connection,so http client create many connection to server?create connection -> send request -> close connection?

The below code works as expected:

httpClient.get().uri("http://127.0.0.1:5230/test")
    .responseSingle(new BiFunction<HttpClientResponse, ByteBufMono, Mono<String>>() {
        @Override
        public Mono<String> apply(HttpClientResponse response, ByteBufMono byteBufMono) {
            return byteBufMono.asString();
        }
    })
    .subscribe();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TongChen