using MySQL autoReconnect=true
configuration results in unhandled access denied errors
#144
Labels
bug
Something isn't working
Took some time tracking down the root cause, but I was getting
com.mysql.cj.exceptions.CJException: Access denied for user
while using the secrets manager MySQL driver for MySQL driver 8.0.31. This is a problem because the error handling for the AWSSecretsManagerMySQLDriver expects a SQLException but the CJException is not a SQLException subclass, so these credential issues were not being automatically handled by the driver.I found that the cause was using the
autoReconnect=true
JDBC parameter. When using this parameter, the MySQL driver ends up taking a separate code fromautoReconnect=false
:When
autoReconnect=false
, thecom.mysql.cj.jdbc.ConnectionImpl.createNewIO
method callscom.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly
instead ofcom.mysql.cj.jdbc.ConnectionImpl.connectWithRetries
. Thecom.mysql.cj.jdbc.ConnectionImpl.connectWithRetries
method ends up throwing a SQLNonTransientConnectionException containing a CJException with a vendorCode equal to the expected error code1045
.So, the immediate fix I've found is to just not use
autoReconnect=true
, turns out its usage is not recommended by MySQL anyway. But it seems like others have found the error detection to be problematic and the error handling here could be improved to unwrap exceptions and check for CJExceptions as well as SQLExceptionsThe text was updated successfully, but these errors were encountered: