Closed tanerilyazov closed 3 years ago
When using multiple datasources based on the guidelines in https://docs.spring.io/spring-boot/docs/2.1.18.RELEASE/reference/html/howto-data-access.html seems to change the behaviour of the connection pools. I've tried multiple ways to configure the connection pools and haven't found a consistent result with anything. Based on the documentation with JDBC4 you don't even need to do additional configuration for the database connection to recover after a restart of the database connection.
Issue: Project with a single datasource and autoconfiguration recovers consistently as documented. Project with multiple custom datasources does not recover, at least not consistently. Based on the logs(enabled debug logging) the behaviour seems a little different.
I've reproduced the issue in this mock project https://github.com/TanerIlyazov/spring-multiple-databases-recovery. There are 2 branches
I've already tried changing the connection pool to TomcatCP and the problem is still apparent.
Thanks for the sample. I had to modify it a bit to ensure that the random number generation did not result in duplicate primary keys in the DB. I have reproduced the problem, though, and can see HikariCP behaving differently in the two cases as you have described. Having said that, it's not clear to me that this is a Spring Boot problem as it appears to be Hikari that's behaving differently and Spring Boot has little influence over that.
To further narrow down the cause of the problem, I would recommend stripping things down further. For example, it would be interesting to know if the problem occurs if you use Spring Framework's JDBC template rather than Hibernate. If would then be interesting to know if the problem still occurs if you use JDBC directly. Similarly, you could try configuring Hikari yourself rather than using Spring Boot's DataSourceBuilder
. If this process of elimination indicates that it is Spring Boot that's causing the problem, please let us know and we can take another look.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
@wilkinsona Hello, sorry it took me some time, but added a branch reproducing the case without spring boot using jdbcTemplate. The databases recover without problem.
Thanks. I see that you’ve also switched from HikariCP to Commons DBCP. That introduces the possibility that the problem may be with HikariCP.
Good catch, I forgot about that. Added another branch without-spring-boot-hikaricp
, where we use HikariCP as the connection pool again, and the results are the same.
Thanks. And what happens if you reinstate Hibernate but keep Spring Boot out of the picture?
@wilkinsona Reinstating Hibernate replicated the problem. :) There's a new branch called without-spring-boot-hibernate
, where the problem is the same.
That's good progress as it eliminates Spring Boot from the possible causes. It's looking to me like it's a Hibernate problem so I'd recommend reporting it to the Hibernate team, ideally after trying to whittle things down further by removing Spring Framework from your example.