io.vertx.sqlclient.ClosedConnectionException: the underlying connection may have been lost unexpectedly.
Version
5.0.0
Context
I have tried everything there is to remedy this: io.vertx.sqlclient.ClosedConnectionException: Failed to read any response from the server, the underlying connection may have been lost unexpectedly.
Trying to create a pool with bit of code that I call inside of a compose (loading the env file) in the mainverticle:
MySQLConnectOptions connectOptions = new MySQLConnectOptions()
.setPort(3306)
.setHost(this.appConfig.getString("MYSQL_HOST"))
.setDatabase(this.appConfig.getString("MYSQL_DB"))
.setUser(this.appConfig.getString("MYSQL_USER"))
.setAuthenticationPlugin(MySQLAuthenticationPlugin.MYSQL_NATIVE_PASSWORD)
.setPassword(this.appConfig.getString("MYSQL_PWD"));
PoolOptions poolOptions = new PoolOptions()
.setMaxSize(5); // Configurable pool size
this.mySQLPool = MySQLBuilder
.pool()
.with(poolOptions)
.connectingTo(connectOptions)
.using(vertx)
.build();
System.out.println("MySQL Pool initialized.");
this.mySQLPool.query("SELECT 1").execute()
.onSuccess(rows -> System.out.println("Successfully connected to MySQL and executed a test query."))
.onFailure(Throwable::printStackTrace);`
I have tried using version 4.5.7. Java 17, 21. I added/removed options. The same result. I ran a test with the JDBC driver and it works fine.
Steps to reproduce
No response
Do you have a reproducer?
No response
which thread executes this ?
check the connection has not been closed in your test because it might have been garbage collected and closed
I have simplified my code to isolate the issue.
I tested with two databases: 10.5.27-MariaDB-ubu2004 (running in local docker container) and MySQL 5.5.9 (remote DB that I want to connect to).
I tested with vertx 5 and 4.5.15. (from https://start.vertx.io/)
This is my start method:
``@Override public Future> start() { Promise> start = Promise.promise(); MySQLConnectOptions connectOptions = new MySQLConnectOptions() .setAuthenticationPlugin(MySQLAuthenticationPlugin.MYSQL_NATIVE_PASSWORD) .setPort(3306) .setHost("localhost") .setDatabase("db") .setUser("root") .setCharset("utf8mb4") .setPassword("pwd"); PoolOptions poolOptions = new PoolOptions() .setMaxSize(5);
Pool pool = MySQLBuilder
.pool()
.with(poolOptions)
.connectingTo(connectOptions)
.using(vertx)
.build();
System.out.println("Pool init thread: " + Thread.currentThread().getName());
pool.query("SELECT VERSION() as version").execute()
.onSuccess(rows -> {
System.out.println("Successfully connected to MySQL and executed a test query." + rows.iterator().next().getString("version"));
vertx.createHttpServer().requestHandler(req -> {
req.response()
.putHeader("content-type", "text/plain")
.end("Hello from Vert.x!");
}).listen(8888).onComplete(http -> {
if (http.succeeded()) {
System.out.println("HTTP server started on port 8888");
start.complete();
} else {
start.fail(http.cause());
}
});
})
.onFailure(err -> {
System.err.println(">>> FAILURE: Failed to connect to MySQL.");
err.printStackTrace();
});
return start.future();
}```
The results : Vertx 4.15 / 5 connects to local DB but not remote one.
The version of mysql is 5.5.9 which according to the docs should be fine. No SSL is required.
The thread is: vert.x-eventloop-thread-1 or similar (not that I think it is the thread since mariaDB worked)
Am I missing something ?
which thread executes this ?
check the connection has not been closed in your test because it might have been garbage collected and closed
can you move the pool outside of the method ?
Hi again, not sure what you are asking. The same code, two different databases: 10.5.27-MariaDB-ubu2004 and MySQL 5.5.9. The first one works, the other does not...I fail to see what moving the code around can do.