r2dbc / r2dbc-pool

Connection Pooling for Reactive Relational Database Connectivity
https://r2dbc.io
Apache License 2.0
331 stars 55 forks source link

Pool not being created or connections not being released after closing them. #204

Closed javiercj93 closed 7 months ago

javiercj93 commented 7 months ago

Bug Report

Versions

Current Behavior

I've followed the Getting started guide but for some reason looks like when I create a connection pool, it is limited to just 10 connections. I've a dummy application which receives a list of items and does a single insert for each of them. I was expecting all the items to be inserted ore wait until a connection is released (according to my configuration) but looks like only the first 10 are inserted and the others are failing to establish a connection.

public Mono<Void> add(List<Fruits> fruits) {
        ConnectionFactory connectionFactory = ConnectionFactories.get(
                ConnectionFactoryOptions.builder().from(ConnectionFactoryOptions.parse(
                                "r2dbc:clickhouse:http://localhost:18123/fruits").build());

        ConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(
                        connectionFactory).maxIdleTime(Duration.ofMillis(3000)).maxSize(50).initialSize(25)
                .build();
        ConnectionPool connectionPool = new ConnectionPool(configuration);
        return Mono.usingWhen(connectionPool.create(),
                connection -> execute(fruits, connection).then(), Connection::close);
    }

My execute function looks like this:

private Flux<Result> execute(List<Fruits> fruits, Connection conn) {
        List<Publisher<? extends Result>> insertStatements = clicks.stream()
                .map(click -> conn.createStatement("insert into fruits values (:name)")
                        .bind("name", fruit.getName()).execute())
                .collect(Collectors.toList());
        return Flux.merge(insertStatements);
    }

First 10 items are inserted, the other 15 throw this exception:

com.clickhouse.client.ClickHouseException: Timeout deadline: 180000 MILLISECONDS, actual: 180006 MILLISECONDS, server ClickHouseNode [uri=http://localhost:18123/fruit]@-4917943
    at com.clickhouse.client.ClickHouseException.of(ClickHouseException.java:168) ~[clickhouse-client-0.5.0.jar:clickhouse-client 0.5.0 (revision: d384444)]
Caused by: org.apache.hc.core5.http.ConnectionRequestTimeoutException: Timeout deadline: 180000 MILLISECONDS, actual: 180006 MILLISECONDS

Expected behavior/code

All the items to be inserted or wait until a connection is released.