I'm writing a POC with spring webflux and google r2dbc cloud sql proxy connector for MySql. Things worked pretty smooth until I'm running a long stress test. After about 40 minutes or so, I kept getting connection closed due to the bad certificate as I have the useSSL=true in the connection url.
I had this issue even if I used useSSL=false.
Here are my settings:
In Gradle specify dependency on spring boot 2.4.0:
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-jetty'
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'com.google.cloud.sql:cloud-sql-connector-r2dbc-mysql:1.2.0'
implementation 'org.springframework:spring-aspects:5.2.8.RELEASE'
implementation 'com.zoominfo:secretutil:1.0.2'
runtimeOnly 'dev.miku:r2dbc-mysql:0.8.2.RELEASE'
runtimeOnly 'mysql:mysql-connector-java:8.0.22'
In mySQL configuration:
@Configuration
@EnableR2dbcRepositories(basePackages = { "com.myorg.repo" })
public class MySQLConfig {
@Bean
@Primary
public ConnectionPool connectionPool() {
String r2dbcURL = String.format("r2dbc:gcp:mysql://%s:%s@%s/%s?useSSL=true",
"username",
"password",
"project name:us-east1:host name",
"database name");
ConnectionFactory connectionFactory = ConnectionFactories.get(r2dbcURL);
ConnectionPoolConfiguration configuration =
ConnectionPoolConfiguration.builder(connectionFactory)
.maxIdleTime(Duration.ofSeconds(60))
.maxLifeTime(Duration.ofSeconds(300))
.initialSize(10)
.maxSize(20)
.maxCreateConnectionTime(Duration.ofSeconds(5))
.validationQuery("SELECT 1")
.build();
return new ConnectionPool(configuration);
}
}
About 60 minutes later:
2020-12-16 14:46:28.149 WARN 93687 --- [ctor-tcp-nio-10] reactor.netty.channel.FluxReceive : [id: 0xedad2630, L:0.0.0.0/0.0.0.0:58027] An exception has been observed post termination, use DEBUG level to see the full stack: io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate
2020-12-16 14:46:28.149 WARN 93687 --- [ctor-tcp-nio-10] d.m.r.mysql.client.ReactorNettyClient : Connection has been closed by peer
2020-12-16 14:46:28.149 ERROR 93687 --- [ctor-tcp-nio-10] reactor.core.publisher.Operators : Operator called default onErrorDropped
dev.miku.r2dbc.mysql.client.MySqlConnectionClosedException: Connection unexpectedly closed
at dev.miku.r2dbc.mysql.client.ClientExceptions.unexpectedClosed(ClientExceptions.java:32) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
...
2020-12-16 14:46:28.150 ERROR 93687 --- [ctor-tcp-nio-10] d.m.r.mysql.client.ReactorNettyClient : Error: Received fatal alert: bad_certificate
javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131) ~[na:na]
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117) ~[na:na]
...
2020-12-16 14:46:28.150 ERROR 93687 --- [ctor-tcp-nio-10] reactor.core.publisher.Operators : Operator called default onErrorDropped
...
dev.miku.r2dbc.mysql.client.MySqlConnectionClosedException: Connection closed
at dev.miku.r2dbc.mysql.client.ClientExceptions.expectedClosed(ClientExceptions.java:36) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]