From 334a93c7609a4f86e3b23556f779f940c3120907 Mon Sep 17 00:00:00 2001 From: gontard Date: Mon, 2 May 2022 12:03:52 +0200 Subject: [PATCH] Fix communication failures with aws-secretsmanager-jdbc Using aws-secretsmanager-jdbc with HikariCP triggers sporadic communication link failures with MySQL. aws-secretsmanager-jdbc library provides JDBC drivers to retrieve DB credentials, host and password from the Amazon Secrets Manager. See: - https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets_jdbc.html - https://github.com/aws/aws-secretsmanager-jdbc By specifying the secret id as a JDBC an URL, and com.amazonaws.secretsmanager.sql.AWSSecretsManagerMySQLDriver as JDBC driver, HikariCP can connect to the MySQL endpoint. But in this stituation, communication link failures occur: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 5,006 milliseconds ago. The last packet sent successfully to the server was 5,007 milliseconds ago. These failures are due a MySQL bug: http://bugs.mysql.com/bug.php?id=75615 which is bypassed by HikariCP when the MySQL driver is used. See: - https://github.com/brettwooldridge/HikariCP/issues/236 - 8af2bc55 (Fix #236 via workaround for MySQL issue http://bugs.mysql.com/bug.php?id=75615, 2015-01-24) This commit applies the same hack for AWSSecretsManagerMySQLDriver. --- src/main/java/com/zaxxer/hikari/pool/PoolBase.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java index 27957c73..74afb019 100644 --- a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java +++ b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java @@ -336,7 +336,7 @@ abstract class PoolBase if (ds != null) { setLoginTimeout(ds); - createNetworkTimeoutExecutor(ds, dsClassName, jdbcUrl); + createNetworkTimeoutExecutor(ds, dsClassName, jdbcUrl, driverClassName); } this.dataSource = ds; @@ -589,12 +589,13 @@ abstract class PoolBase } } - private void createNetworkTimeoutExecutor(final DataSource dataSource, final String dsClassName, final String jdbcUrl) + private void createNetworkTimeoutExecutor(final DataSource dataSource, final String dsClassName, final String jdbcUrl, final String driverClassName) { // Temporary hack for MySQL issue: http://bugs.mysql.com/bug.php?id=75615 if ((dsClassName != null && dsClassName.contains("Mysql")) || (jdbcUrl != null && jdbcUrl.contains("mysql")) || - (dataSource != null && dataSource.getClass().getName().contains("Mysql"))) { + (dataSource != null && dataSource.getClass().getName().contains("Mysql")) || + "com.amazonaws.secretsmanager.sql.AWSSecretsManagerMySQLDriver".equals(driverClassName)) { netTimeoutExecutor = new SynchronousExecutor(); } else {