good night,
I'm trying to figure out why the connection pool only grow as long as the application run...
In my application(SpringMVC) I have created a bean responsable for send http requests to third parties and works well, except ConnectionProvider(DefaultPooledConnectionProvider) just grows the channelPools and never disposes. In the bean definition I create a attribute of type ConnectionProvider and pass to new HttpClient everytime I need to perform a http request.
Object creation
@Component("httpClientReactor")
public class HttpClientReactor extends AbstractDispatcheHttp {
private static Logger LOG = LoggerFactory.getLogger(HttpClientReactor.class);
private ConnectionProvider connectionProvider;
private HttpReactorConfig reactorConfig;
private SslContext sslContext;
static final String EMPTY = "";
static final String START_URL_QUERY = "?";
static final String URL_PROTOCOL_HOST_SEPARATOR = "://";
static final String URL_HOST_PORT_SEPARATOR = ":";
static long end = 0L;
static final Map<String, RateLimiter> LIMITER = new HashMap();
static final AtomicInteger RSP;
static final AtomicInteger RSP_E;
static final AtomicInteger ERR;
public HttpClientReactor() {
}
@PostConstruct
void config() throws SSLException, NoSuchAlgorithmException {
this.reactorConfig = (HttpReactorConfig)this.configurationManager.getConfigOrNewInstance(HttpReactorConfig.class);
this.connectionProvider = ((ConnectionProvider.Builder)((ConnectionProvider.Builder)((ConnectionProvider.Builder)((ConnectionProvider.Builder)((ConnectionProvider.Builder)((ConnectionProvider.Builder)ConnectionProvider.builder("custom").pendingAcquireMaxCount(this.reactorConfig.pendingAcquireQueueSize)).maxConnections(this.reactorConfig.maxConnections)).maxIdleTime(Duration.ofMillis(this.reactorConfig.maxIdleTimeInMs))).maxLifeTime(Duration.ofMillis(this.reactorConfig.maxLifeTimeInMs))).pendingAcquireTimeout(Duration.ofMillis(this.reactorConfig.pendingAcquireTimeoutInMs))).evictInBackground(Duration.ofMillis(this.reactorConfig.evictInBackgroundInMs))).build();
this.sslContext = SslContextBuilder.forClient().clientAuth(ClientAuth.NONE).ciphers(this.dispatcherConfig.sslSupportedAlgs()).trustManager(this.dispatcherConfig.isTrustAllSsl() ? InsecureTrustManagerFactory.INSTANCE : TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())).build();
}
And how I use:
HttpClient.RequestSender requestSender = (HttpClient.RequestSender)((HttpClient)((HttpClient)((HttpClient)httpClient.baseUrl((String)urlPath.getKey()).responseTimeout(Duration.ofSeconds(requestVariables.request.getTimeOut())).headers(consumer.headerProducer).doOnRequest(consumer.onRequest).doOnChannelInit(consumer.channelConfigurer)).doOnConnect(consumer.connectionConsumer)).doOnResolveError(consumer.resolverError)).doOnError(consumer.errorRequest, consumer.errorResponse).doAfterResponseSuccess(consumer.afterResponseSucess).followRedirect(false).request(HttpMethod.valueOf(requestVariables.request.getMethod().name())).uri((String)urlPath.getValue());
LOG.debug("Request {} prepared", requestVariables.request);
ByteBufFlux publisher = requestSender.send((httpRequest, out) -> {
return out.sendObject(requestBody != null ? Unpooled.wrappedBuffer(requestBody) : null).then();
}).responseContent();
publisher.subscribe(consumer.bodyConsumer);
Heap dump analisis shows this in production:
Problem Suspect 2
18,282 instances of reactor.netty.internal.shaded.reactor.pool.SimpleDequePool, loaded by Module Class Loader for module app.war occupy 11,551,108,616 (36.83%) bytes.
What I'm doing wrong?
PS. version 1.0.22 of reactor-netty-http [1]: https://i.stack.imgur.com/8QnNB.png