Closed leewp closed 3 years ago
sigh, connection pool acquired size will be -1
Now I use this.ref.release , not this.release, the program runs normally more than 48h
Mono.delay(Duration.ofMinutes(2))
.doOnSubscribe(subscription -> checkReleaseSubscription = subscription)
.filter(closed -> !this.closed)
.doOnNext(aLong -> logger.info("after 2m, connection not be closed, now release it (use subscription and ref.release)"))
.flatMap(aLong -> this.ref.release())
.subscribe();
Thanks, I learned a lot from r2dbc-pool, it's a great project.
With my modification, my program runs normally more than 7 days, It's work for me, and I will use r2dbc in my all new project.
Now I close this issue, when u want to fix it, or need my help, just open it.
Bug Report
Versions
Current Behavior
I used spring boot with spring data r2dbc build a service, approximately 5,000,000 requests(select and update) per day 。First, everything is ok, but after 3-7 days,any requests will time out ,from spring boot 2.3.x to now, every time the version is updated, I will try to see if it solves the problem . Until now(spring boot 2.5.0), the problem exist.
So I spent some time to study the source code of r2dbc-pool,then I found when problem happend,
the value of
is alway
the acquired 10 connection never be released, so any sql request will be timeout.
Stack trace
``` org.springframework.dao.DataAccessResourceFailureException: Failed to obtain R2DBC Connection; nested exception is io.r2dbc.spi.R2dbcTimeoutException: Connection Acquisition timed out after 5000ms ```It's easy to reproduce the problem in my production environment , spend some time, I found a way where the problem can be reproduced, I give the test conditions below.
Table schema
Input Code
``` CREATE TABLE `demo` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='demo table'; ```Steps to reproduce
The following code is only used to simulate the problem ,It's just one kind of situation that reproduce the problem , and it's different from my production environment .
Maybe it's bug of spring data r2dbc, maybe it's bug of reactor
Input Code
```java DemoRepository.java //It is only used to simulate a certain situation and has no practical meaning @Query("select sleep(0.1)") MonoExpected behavior/code
I expect the idleSize is 10 and acquiredSize is 0 when no sql request, but now I found some pooledConnection never be released
Possible Solution
I like reactive, like webflux, like r2dbc , but this problem caused my program to died(always timeout, can't read or save data) several times. for use r2dbc in my project, I found a solution suitable for my project , add a timer check in PooledConnection(PooledRef ref)
and dispose it when PooledConnection.release is subscribed
After 24h, I found some
in spring.log and the idleSize will often be 10, now it looks like no pooled connection never be release, I will report the result after 7 days
Additional context