2

Environment

Hikari CP Version : 3.4.1
JDK version: 1.8.0_251
Database: Azure SQL
SpringBoot Version: 2.2.2 RELEASE
MS-SQL JDBC Driver version:- 8.4.1-jre8

I am working on a Spring Boot app where I have a requirement for configuring the auto failover of database and we are leveraging Azure Failover Groups. The application is connected to the primary database and when the manual failover of the primary server is done, the application should connect to secondary server which is now the new primary.

Below is my JDBC connection string and Hikari properties:

logging.level.org.springframework.jdbc.core=DEBUG

spring.datasource.url=jdbc:sqlserver://<FailoverGroupname>.database.windows.net:1433;database=<DatabaseName>;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
spring.datasource.username=demo
spring.datasource.password=***

spring.datasource.initialization-mode=always

hibernate.hikari.minimumIdle=0
hibernate.hikari.maxPoolSize=1
hibernate.hikari.autoCommit=false
hibernate.hikari.initializationFailTimeout=3000
hibernate.hikari.connectionTestQuery=SELECT 1

When the application is started, below is the analysis:

  1. Hikari has a valid connection in the pool
  2. Spring JPA Transaction pulls the connection from the pool
  3. Data is getting persisted in database successfully
  4. next, Manual Failover is done
  5. txn.begin(), throws exception
  6. Broken Pipe Write Failed Exception
  7. Connection is closed (SQLServerException: The connection is closed)
  8. Connection remains closed till the application is running

Expectation:
Since pool has come in bad state, the connections after getting closed should be recovered and connect to the new primary database that serves as backup

Does anyone knows how can I re-establish the closed connections to auto reconnect to backup database.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user2594
  • 386
  • 1
  • 5
  • 18
  • Java caches DNS lookups, you may need to reduce the TTL of the DNS cache, see for example https://stackoverflow.com/questions/1256556/how-to-make-java-honor-the-dns-caching-timeout and https://stackoverflow.com/questions/42976379/changing-java-dns-cache-settings – Mark Rotteveel Sep 14 '20 at 16:15
  • @Mark Rotteveel Edited the values for both the ttl in jre/lib/security/java.security file and restarted the app and still the connections are getting closed and not redirecting to updated DNS – user2594 Sep 14 '20 at 17:12
  • Hi, in my previous test, it seems that Hikaricp will reconnect to the failover group automatically. My Hikari CP Version : 3.4.5. – Joseph Xu Sep 15 '20 at 07:07

0 Answers0