Skip to content

Clickhouse jdbc + client throwing Cannot invoke "java.net.Socket.setSoTimeout(int)" because "sock" is null #2323

Open
@Sameerlaag

Description

@Sameerlaag

Describe the bug

Hi, I'm building a Spring Boot 3 + Java 21 app that connects to a ClickHouse instance running on another machine.

I can successfully ping the ClickHouse server directly from the machine, but when I try to connect via the Java app using the JDBC + client, I get a connection error.

The issue seems to have been fixed here: #2206

However, I'm still experiencing it even with version 0.8.4 of the client.

Code example

    @Bean(name = "clickHouseClient")
    public Client clickHouseClient() {
        return new Client.Builder()
                .addEndpoint(url)
                .setUsername(username)
                .setPassword(password)
                .setRootCertificate(certificatePath)
                .setConnectTimeout(30, ChronoUnit.SECONDS)
                .setSocketTimeout(30, ChronoUnit.SECONDS)
                .setMaxConnections(10)
                .setMaxRetries(3)
                .build();

//In my repo

    private final String GET_CH_ERROR = """
            SELECT
                1
            FROM deltaLake(errors, filename = 'missions')
            LIMIT 2
            """;

    public List<GenericRecord> executeQuery(String sql) {
        return clickHouseClient.queryAll(sql);
    }

    @Override
    public List<ErrorModel> getErrors(GlobalFilterModel globalFilterModel) {
        this.executeQuery(GET_CH_ERROR);
        return List.of();
    }
    }
    clickhouse:
      hikari:
        connection-timeout: 50000  # 50 seconds
        validation-timeout: 5000   # Timeout for validation query (if used)
        maximum-pool-size: 5
      url: http://internal.censored.url:80
      jdbc-url: jdbc:clickhouse:http://internal.censored.url:80/default
      username: admin
      password: default
      certificate-path: ../application/src/main/resources/clickhouse-cert.pem
      initialization-mode: never
      driver-class-name: com.clickhouse.jdbc.ClickHouseDriver

Error log

java.lang.NullPointerException: Cannot invoke "java.net.Socket.setSoTimeout(int)" because "sock" is null
        at org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:165) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:450) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:162) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:172) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:142) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:192) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec.execute(HttpRequestRetryExec.java:113) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ContentCompressionExec.execute(ContentCompressionExec.java:152) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.RedirectExec.execute(RedirectExec.java:116) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:170) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:87) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:55) ~[httpclient5-5.3.1.jar:5.3.1]
        at org.apache.hc.client5.http.classic.HttpClient.executeOpen(HttpClient.java:183) ~[httpclient5-5.3.1.jar:5.3.1]
        at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:415) ~[client-v2-0.8.4.jar:client-v2 0.8.4 (revision: 63be1b9)]
        at com.clickhouse.client.api.Client.lambda$query$10(Client.java:1705) ~[client-v2-0.8.4.jar:client-v2 0.8.4 (revision: 63be1b9)]
        at com.clickhouse.client.api.Client.runAsyncOperation(Client.java:2134) ~[client-v2-0.8.4.jar:client-v2 0.8.4 (revision: 63be1b9)]
        at com.clickhouse.client.api.Client.query(Client.java:1748) ~[client-v2-0.8.4.jar:client-v2 0.8.4 (revision: 63be1b9)]
        at com.clickhouse.client.api.Client.queryAll(Client.java:1829) ~[client-v2-0.8.4.jar:client-v2 0.8.4 (revision: 63be1b9)]
        at com.clickhouse.client.api.Client.queryAll(Client.java:1859) ~[client-v2-0.8.4.jar:client-v2 0.8.4 (revision: 63be1b9)]


javax.net.ssl|DEBUG|04|Keep-Alive-Timer|2025-04-22 15:31:18.755 CEST|SSLSocketImpl.java:577|duplex close of SSLSocket
javax.net.ssl|WARNING|04|Keep-Alive-Timer|2025-04-22 15:31:18.759 CEST|SSLSocketImpl.java:1220|input stream close depletion failed (
"throwable" : {
  java.net.SocketTimeoutException: Read timed out
        at java.base/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:278)
        at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:304)
        at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:346)
        at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:796)
        at java.base/java.net.Socket$SocketInputStream.read(Socket.java:1099)
        at java.base/java.net.Socket$SocketInputStream.read(Socket.java:1093)
        at java.base/sun.security.ssl.SSLSocketInputRecord.deplete(SSLSocketInputRecord.java:509)
        at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.readLockedDeplete(SSLSocketImpl.java:1216)
        at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.deplete(SSLSocketImpl.java:1191)
        at java.base/sun.security.ssl.SSLSocketImpl.bruteForceCloseInput(SSLSocketImpl.java:808)
        at java.base/sun.security.ssl.SSLSocketImpl.duplexCloseOutput(SSLSocketImpl.java:664)
        at java.base/sun.security.ssl.SSLSocketImpl.close(SSLSocketImpl.java:584)
        at java.base/sun.net.www.http.HttpClient.closeServer(HttpClient.java:1139)
        at java.base/sun.net.www.protocol.https.HttpsClient.closeServer(HttpsClient.java:442)
        at java.base/sun.net.www.http.KeepAliveCache.run(KeepAliveCache.java:282)
        at java.base/java.lang.Thread.run(Thread.java:1583)
        at java.base/jdk.internal.misc.InnocuousThread.run(InnocuousThread.java:186)}

)
javax.net.ssl|DEBUG|04|Keep-Alive-Timer|2025-04-22 15:31:18.760 CEST|SSLSocketImpl.java:1775|close the SSL connection (passive)

Configuration

Environment

  • Client version: 0.8.4
  • Language version: 21
  • OS: UBUNTU 22.04

Now i did have the same issue going through JDBC, and i switched to client expecting a better result, but it's the same.

Any clue how to fix this ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    buginvestigatingInvestigation of a root cause is on going

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions