I have a Quarkus application that uses AgroalDataSource to connect to a ClickHouse database. The application runs fine when I launch it normally and i can connect to clickhouse and got result, but when I build a native image using GraalVM and run the API, I encounter the following error:
redis-client, resteasy, resteasy-jackson, smallrye-context-propagation, smallrye-health, smallrye-reactive-messaging, smallrye-reactive-messaging-kafka, vertx]
23:46:46 WARN traceId=, parentId=, spanId=, sampled= [io.ag.pool] (agroal-11) Datasource '<default>': Failed to get service com.clickhouse.client.ClickHouseSslContextProvider, server ClickHouseNode [uri=https hidden url]@-1477137086
java.sql.SQLException: Failed to get service com.clickhouse.client.ClickHouseSslContextProvider, server ClickHouseNode [uri=https hidden url]@-1477137086
at com.clickhouse.jdbc.SqlExceptionUtils.handle(SqlExceptionUtils.java:85)
at com.clickhouse.jdbc.SqlExceptionUtils.create(SqlExceptionUtils.java:31)
at com.clickhouse.jdbc.SqlExceptionUtils.handle(SqlExceptionUtils.java:90)
at com.clickhouse.jdbc.internal.ClickHouseConnectionImpl.getServerInfo(ClickHouseConnectionImpl.java:93)
at com.clickhouse.jdbc.internal.ClickHouseConnectionImpl.<init>(ClickHouseConnectionImpl.java:298)
at com.clickhouse.jdbc.internal.ClickHouseConnectionImpl.<init>(ClickHouseConnectionImpl.java:241)
at com.clickhouse.jdbc.ClickHouseDriver.connect(ClickHouseDriver.java:145)
at com.clickhouse.jdbc.ClickHouseDriver.connect(ClickHouseDriver.java:41)
at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:226)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:536)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:517)
at [email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:75)
at [email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at [email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at [email protected]/java.lang.Thread.run(Thread.java:833)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.windows.WindowsPlatformThreads.osThreadStartRoutine(WindowsPlatformThreads.java:178)
Code:
Here is the relevant code snippet:
import io.agroal.api.AgroalDataSource;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@Path("")
public class ExampleRessource {
@Inject
AgroalDataSource dataSource;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getTime() {
String toReturn=null;
try (Connection con = dataSource.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT name FROM system.databases")) {
try (ResultSet rs = ps.executeQuery();) {
rs.next();
toReturn = "Current time: " + rs.getString(1);
System.out.println(toReturn);
}
} catch (SQLException e) {
e.printStackTrace();
}
return toReturn;
}
}
My POM.XML
<properties>
<maven.compiler.release>17</maven.compiler.release>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.2.2.Final</quarkus.platform.version>
<jdbc.clickhouse.version>3.0.1</jdbc.clickhouse.version>
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
<clickhouse.jdbc.version>0.4.1</clickhouse.jdbc.version>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.jdbc</groupId>
<artifactId>quarkus-jdbc-clickhouse</artifactId>
<version>${jdbc.clickhouse.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<classifier>http</classifier>
<version>${clickhouse.jdbc.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
etc...
What I’ve Tried:
- The application runs fine when launched normally.
- The native image is generated without any issues.
- The error occurs only when running the native image.
Additional Information:
- I am using GraalVM 22.3.0 to build the native image.
- i tried to run the application with recent graalvm and latest version of quarkus but got same error
- The ClickHouse database is accessed over HTTPS, by adding ?ssl=true in the url.
Question:
How can I resolve this SQLException when running the native image? Is there a specific configuration or dependency that I need to include for GraalVM to properly handle the ClickHouse connection?
2