r2dbc / r2dbc-pool

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

Connection Closed exception #154

Closed menakaprabu closed 2 years ago

menakaprabu commented 2 years ago
  1. I am getting same ConnectionClosed exception even after setting the maxIdleTime as Duration.Zero. When we talk about disposal, it is closing the idle connection in the pool right? Closing the idle connection is required or not ? If required, then why are we throwing ConnectionClosed exception ? Note: Query execution is successful even after the exception. My configuration looks like this ConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder() .option(ConnectionFactoryOptions.DRIVER, "mssql") .option(ConnectionFactoryOptions.HOST, hostname) .option(ConnectionFactoryOptions.USER, username) .option(ConnectionFactoryOptions.PASSWORD, password()) .option(ConnectionFactoryOptions.PORT, portnumber) .option(ConnectionFactoryOptions.DATABASE, dbname) .build()); ConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(connectionFactory) .initialSize(10) .maxSize(20) .maxIdleTime(Duration.ZERO) .build();

  2. I have tried with r2dbc-pool with version 0.9.0.RELEASE and setting the maxIdleTime as maxIdleTime(Duration.ofMinutes(-1)) is also throwing me the ConnectionClosed exception.

  3. How to create the pool ? I see the doc with both with driver as pool and without. Which is the correct one?

ConnectionFactory pooledConnectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder() .option(DRIVER,"pool") .option(PROTOCOL,"postgresql") // driver identifier, PROTOCOL is delegated as DRIVER by the pool. .option(HOST,"…") .option(PORT,"…") .option(USER,"…") .option(PASSWORD,"…") .option(DATABASE,"…") .build()

OR

ConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder() .option(DRIVER,"postgresql") .option(HOST,"…") .option(PORT,"…") .option(USER,"…") .option(PASSWORD,"…") .option(DATABASE,"…") .build());

// Create a ConnectionPool for connectionFactory ConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(connectionFactory) .maxIdleTime(Duration.ofMillis(1000)) .maxSize(20) .build();

Thanks!

mp911de commented 2 years ago

The pool has a retry count of 1. If the first allocation attempt fails, the pool tries to allocate another connection. If the second connection is broken as well, then the allocation fails with an exception from the driver. We improved idle behavior with #167 to evict idle connections. Please either upgrade to a newer version or increase the retry count (acquireRetry=5).