4

I am new to spring boot so doesn't know much about configuration in application.properties or pom.xml . I'm trying to do a CRUD operation in MySQL DB hosted in Azure VM. Once I start my spring-boot application and perform a DB operation, it works fine the first time. After a while, say 4-5 mins, when another operation is performed, then the springboot application fails to connect to the DB and throws Exception.

PSB the log:

2019-12-23 14:43:00.063 DEBUG 64148 --- [http-nio-4400-exec-5] o.s.web.servlet.DispatcherServlet        : GET "/rest/path/getFrequentDetail?queryParam1=value1&queryParam2=value2", parameters={masked}
2019-12-23 14:43:00.063 DEBUG 64148 --- [http-nio-4400-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<com.bla.bla> com.bla.bla(java.lang.String,java.lang.String) throws java.io.IOException
2019-12-23 14:43:00.064 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.e.t.internal.TransactionImpl         : On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2019-12-23 14:43:00.064 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.e.t.internal.TransactionImpl         : begin
2019-12-23 14:43:05.073  WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase          : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@503a164d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:10.077  WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase          : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@56e33182 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:15.079  WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase          : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@43689c2d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:20.082  WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase          : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@306934d0 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:25.085  WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase          : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@7754c08f (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:30.087  WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase          : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@3a33fdce (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:30.091 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : Unable to acquire JDBC Connection [n/a]
java.sql.SQLTransientConnectionException: HikariPool-2 - Connection is not available, request timed out after 30024ms.
        at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:697)

application.properties

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# Hikari parameters
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000

spring.datasource.initialize=true
spring.datasource.schema=classpath:schema.sql
spring.batch.initialize-schema=ALWAYS
spring.batch.job.enabled: false

I've searched through the internet for similar issues and mostly it was related to connection remaining open or MySQL timeout configuration. Both of these seems fine in my case.

All operations are done using JPA. Timeout in mysql is fairly high:

  • innodb_lock_wait_timeout 50
  • wait_timeout 28800
  • mysqlx_wait_timeout 28800

Please help.

Debadatta Meher
  • 83
  • 2
  • 10
  • Is your connection to the Azure VM stable? I.e. continuous ping = no dropped packets? – SledgeHammer Dec 24 '19 at 05:42
  • This sounds like a connection was held out of the pool for an excessively long time and then used. I suggest enabling the leakDetectionThreshold and enabling DEBUG level logging for the com.zaxxer.hikari package. Refer this for more detail https://github.com/brettwooldridge/HikariCP/issues/1121 – MyTwoCents Dec 24 '19 at 06:50
  • @SledgeHammer: Other applications are also deployed in the Azure VM, and the these applications doesn't have this issue. I assume the connection to Azure VM is stable. – Debadatta Meher Dec 24 '19 at 07:01
  • 1
    I've discussed with the DBA and I got to know that the time-limit for an idle connection is configured to be 3 minutes, that is why it is unable to make the connection again after some time(second request as per my scenario). – Debadatta Meher Dec 24 '19 at 08:38

0 Answers0