The spring boot actuator gets the jdbc Connection when executing the DataSource health check, and calls connection.getMetaData().getDatabaseProductName(), which does not actually operate the database, resulting in the connection's effective time not being renewal.
When returning to the connection pool, Druid will change lastActiveTimeMillis to the latest time, which will cause the cleanup thread to mistake the connection for its validity, so it has not been cleaned up.
In fact, it has passed the survival time. It will disturb the cleanup of the connection pool, then the next time you get this connection, it will be invalid for MySql, throwing a CommunicationsException exception.
If I just get the connection from the connection pool and return it to the connection pool, nothing is done. This will also update the time of 'lastActiveTimeMillis', which will disturb the recycling thread to determine whether the connection is invalid or not.
Description
Exception analysis
The
spring boot actuator
gets the jdbc Connection when executing the DataSource health check, and callsconnection.getMetaData().getDatabaseProductName()
, which does not actually operate the database, resulting in the connection's effective time not being renewal.When returning to the connection pool, Druid will change
lastActiveTimeMillis
to the latest time, which will cause the cleanup thread to mistake the connection for its validity, so it has not been cleaned up.In fact, it has passed the survival time. It will disturb the cleanup of the connection pool, then the next time you get this connection, it will be invalid for MySql, throwing a
CommunicationsException
exception.If I just get the connection from the connection pool and return it to the connection pool, nothing is done. This will also update the time of 'lastActiveTimeMillis', which will disturb the recycling thread to determine whether the connection is invalid or not.