r2dbc / r2dbc-pool

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

Connection unexpectedly closed #153

Closed menakaprabu closed 2 years ago

menakaprabu commented 2 years ago

I am using r2dbc-pool (0.8.8.RELEASE) where I am getting Connection unexpectedly closed exception for every 30 mins from application launch time. It is not happening without using pool. I am using mssql protocol. Please suggest, what I am missing here.

mp911de commented 2 years ago

The pool has a default max idle time of 30 minutes. If you configure Duration.ZERO then background disposal is disabled. Please note that in version 0.9 the behavior was changed. To disable background disposal, with version 0.9 you need to configure a negative timeout such as -1.

menakaprabu commented 2 years ago

Thanks, Mark for the quick response. I have few follow up questions:

  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!

On Tue, Jan 25, 2022, 12:57 AM Mark Paluch @.***> wrote:

Closed #153 https://github.com/r2dbc/r2dbc-pool/issues/153.

— Reply to this email directly, view it on GitHub https://github.com/r2dbc/r2dbc-pool/issues/153#event-5948166722, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJIZE6OLQ7SQTPKC2KRY2HTUXZQW5ANCNFSM5MW3WWIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>