Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R2DBC Pool does not guarantee minIdle #200

Open
pkgonan opened this issue Oct 29, 2023 · 4 comments
Open

R2DBC Pool does not guarantee minIdle #200

pkgonan opened this issue Oct 29, 2023 · 4 comments

Comments

@pkgonan
Copy link

pkgonan commented Oct 29, 2023

Bug Report

First, Error Detected

CannotCreateTransactionException
Could not open R2DBC Connection for transaction
스크린샷 2023-10-29 오후 11 42 45 스크린샷 2023-10-29 오후 11 42 58

Second, We found R2DBC Pool Status
Oddly enough, there is no guarantee of R2DBC Pool minIdle on a particular instance. The number of R2DBC Pool idle connections is not being maintained.

Only 1 out of 3 instances is anomalous. Please check the image below.
스크린샷 2023-10-29 오후 11 18 47

Third, Source Code

@Configuration
internal class R2dbcConfiguration internal constructor(
    @Value("\${payment-platform.r2dbc.host}")
    private val host: String,
    @Value("\${payment-platform.r2dbc.port}")
    private val port: Int,
    @Value("\${payment-platform.r2dbc.username}")
    private val username: String,
    @Value("\${payment-platform.r2dbc.password}")
    private val password: String,
    @Value("\${payment-platform.r2dbc.database}")
    private val database: String,
): AbstractR2dbcConfiguration() {

    companion object {
        const val CONNECTION_FACTORY_PROVIDER_DRIVER_NAME = MariadbConnectionFactoryProvider.MARIADB_DRIVER

        private const val MAX_SIZE = 20
        private const val INITIAL_SIZE = MAX_SIZE
        private val CONNECTION_POOL_MAX_LIFE_TIME = Duration.ofSeconds(30)
    }

    @Bean
    override fun connectionFactory(): ConnectionFactory {
        return ConnectionFactories.get(
            ConnectionFactoryOptions.builder()
                .option(ConnectionFactoryOptions.SSL, false)
                .option(ConnectionFactoryOptions.HOST, host)
                .option(ConnectionFactoryOptions.PORT, port)
                .option(ConnectionFactoryOptions.USER, username)
                .option(ConnectionFactoryOptions.PASSWORD, password)
                .option(ConnectionFactoryOptions.DATABASE, database)
                .option(ConnectionFactoryOptions.DRIVER, PoolingConnectionFactoryProvider.POOLING_DRIVER)
                .option(ConnectionFactoryOptions.PROTOCOL, CONNECTION_FACTORY_PROVIDER_DRIVER_NAME)
                .option(PoolingConnectionFactoryProvider.INITIAL_SIZE, INITIAL_SIZE)
                .option(PoolingConnectionFactoryProvider.MAX_SIZE, MAX_SIZE)
                .option(PoolingConnectionFactoryProvider.MIN_IDLE, MAX_SIZE / 2)
                .option(PoolingConnectionFactoryProvider.MAX_ACQUIRE_TIME, Duration.ofSeconds(2))
                .option(PoolingConnectionFactoryProvider.MAX_CREATE_CONNECTION_TIME, Duration.ofSeconds(2))
                .option(PoolingConnectionFactoryProvider.MAX_LIFE_TIME, CONNECTION_POOL_MAX_LIFE_TIME)
                .option(PoolingConnectionFactoryProvider.VALIDATION_DEPTH, ValidationDepth.REMOTE)
                .option(PoolingConnectionFactoryProvider.MAX_VALIDATION_TIME, Duration.ofSeconds(2))
                .option(MariadbConnectionFactoryProvider.LOOP_RESOURCES, LoopResources.create("r2dbc", LoopResources.DEFAULT_IO_SELECT_COUNT, LoopResources.DEFAULT_IO_WORKER_COUNT, true, false))
                .build()
        )
    }
}

Versions

  • Driver: r2dbc-pool "1.0.1.RELEASE", Spring Boot WebFlux
  • Database: Aurora MySQL 8
  • Java: 17
  • OS: Mac OS
@pkgonan pkgonan changed the title It does not guarantee minIdle R2DBC Pool does not guarantee minIdle Oct 29, 2023
@pkgonan
Copy link
Author

pkgonan commented Oct 29, 2023

@mp911de @pderop
Hi.

Do you know about this issue?

I would appreciate any suggestions on how to fix it.

@pderop
Copy link

pderop commented Oct 30, 2023

@pkgonan ,

Hi,

Thank you for reaching out, but I'm unsure how I can help here, so I will let @mp911de comment on this issue.
If you suspect that the problem may be related to the reactor-pool project, I'd recommend isolating the issue there first and, if needed, submit a separate issue in the reactor-pool GH project with the details.

Thank you.

@mp911de
Copy link
Member

mp911de commented Nov 1, 2023

MinIdle is being considered upon connection pool warmup. Is your application calling ConnectionPool.warmup() and awaiting the result?

Regarding the exception, can you attach the stack trace so that we can direct the issue into the appropriate component?

@ikarsokolov
Copy link

ikarsokolov commented Sep 26, 2024

For me minIdle is not working as expected too. After maxIdleTime all idle connections in the pool are terminated leaving 0 idle connections available.

Pool warmup is called during application startup. But it actually opens initialSize connections not minIdle.

It looks like minIdle setting have zero effect on actual pool behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants