Skip to content

Clickhouse Closed unexpectedly. Code: 33. DB::Exception: Cannot read all data. #2479

Open

Description

@Narthexes

Leaving this as a footprint here in case anyone else runs into this head-scratcher.

I was trying to use the CH Java Client-v2 library to write RowBinary, and was running into this DB Exception error repeatedly even though my data was set up correctly according to the unit tests in https://github.com/ClickHouse/clickhouse-java/blob/main/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java#L177

Code:

        client = new Client.Builder()
                .addEndpoint(Protocol.HTTP, "####", 8123, false)
                .setUsername(builder.user)
                .setPassword(builder.pass)
                .setDefaultDatabase("public")
                .build();

    TableSchema schema = client.getTableSchema(table);

    ClickHouseFormat format = ClickHouseFormat.RowBinary;
    InsertSettings settings = new InsertSettings();
    try (InsertResponse response = client.insert(table, out -> {
        RowBinaryFormatWriter w = new RowBinaryFormatWriter(out, schema, format);

        for(Message message : messages){
            Field[] row = transformMessage(message);
            for (Field field : row) {
                w.setValue(field.index, field.value);
            }
            w.commitRow();
        }
    }, format, settings).get()) {
        logger.info("Rows written: " + response.getWrittenRows());
    }

I can't show it all, but basically it was pretty inline with the unit test

Error message:
clickhouse Closed unexpectedly. Code: 33. DB::Exception: Cannot read all data. Bytes read: 1648. Bytes expected: 2097151

Unfortunately this error message was pretty vague, and I can't recreate anymore to get the full dump. The only thing I can notice was odd is that I was trying to insert a single row, and on average that has only 600 bytes, but it expected 2 million... which is way overestimated.

Solution:
This error was resolved after i specified the bufferSize in the client configuration.

        int bufferSize = (7 * 65500);
        client = new Client.Builder()
                .addEndpoint(Protocol.HTTP, "####", 8123, false)
                .setUsername(builder.user)
                .setPassword(builder.pass)
                .setDefaultDatabase("public")
                .setSocketSndbuf(bufferSize)
                .setSocketRcvbuf(bufferSize)
                .setClientNetworkBufferSize(bufferSize)
                .build();

And remains resolved even after I remove the buffer size config and rerun the application.

So, I don't know why or how this fixed it, but i hope it helps anyone else running into this specific issue

Activity

  1. added
    client
    connectivity
    on Jun 30, 2025
  2. chernser commented on Jun 30, 2025

    @chernser
    Contributor

    @Narthexes Thank you for reporting!

    This probably happens because buffer is too small and may be a timeout happens in the call chain.
    We have update default value recently to fix another problem.
    We will experiment with this values to understand a root cause.

  3. github-actions commented on Jul 1, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!

  4. added this to the 0.12.0 milestone on Jul 22, 2026
  5. added
    planned_work
    on Nov 18, 2026
  6. polyglotAI-bot commented on Nov 28, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — needs info from the reporter
    Ask the reporter for the items in the Analysis. The run does not support a buffer-size cause: the same rows arrive with 512-byte buffers, the default buffers, and the reporter's buffer sizes.

    Analysis: Bytes expected: 2097151 is much larger than a one-row body, so the server read a size from bytes that are not a size: the body did not match the columns of the table. The buffer sizes do not change the bytes that RowBinaryFormatWriter.commitRow() writes (client-v2/src/main/java/com/clickhouse/client/api/data_formats/RowBinaryFormatWriter.java:89-104). Missing: the client version, the table DDL (column types and defaults), and the Java type of each value that transformMessage gives.

    Reproduction: complete program and output

    Changed from the issue's steps: the table and the values are examples, because the issue does not give them.

    import com.clickhouse.client.api.Client;
    import com.clickhouse.client.api.data_formats.RowBinaryFormatWriter;
    import com.clickhouse.client.api.insert.InsertResponse;
    import com.clickhouse.client.api.insert.InsertSettings;
    import com.clickhouse.client.api.metadata.TableSchema;
    import com.clickhouse.client.api.query.GenericRecord;
    import com.clickhouse.data.ClickHouseFormat;
    import java.time.LocalDateTime;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    
    public class Repro {
        static final String URL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
        static final String PASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
        static final String TABLE = "test_issue2479";
    
        // Inserts `rows` rows with RowBinaryFormatWriter, as in the issue, then reads back the row count and the byte sum.
        static void run(String name, Integer bufferSize, int rows) {
            Client.Builder b = new Client.Builder().addEndpoint(URL).setUsername("default").setPassword(PASSWORD);
            if (bufferSize != null) {
                b.setSocketSndbuf(bufferSize).setSocketRcvbuf(bufferSize).setClientNetworkBufferSize(bufferSize);
            }
            try (Client client = b.build()) {
                client.execute("TRUNCATE TABLE " + TABLE).get().close();
                TableSchema schema = client.getTableSchema(TABLE);
                ClickHouseFormat format = ClickHouseFormat.RowBinary;
                char[] filler = new char[500];
                Arrays.fill(filler, 'x');
                String text = new String(filler);
                try (InsertResponse response = client.insert(TABLE, out -> {
                    RowBinaryFormatWriter w = new RowBinaryFormatWriter(out, schema, format);
                    for (int r = 0; r < rows; r++) {
                        w.setValue(1, (long) r);
                        w.setValue(2, text + r);
                        w.setValue(3, r % 2 == 0 ? null : "n" + r);
                        w.setValue(4, LocalDateTime.of(2025, 6, 30, 12, 0, 0));
                        w.setValue(5, Arrays.asList("a", "bb", "ccc"));
                        w.setValue(6, Collections.singletonMap("k", r));
                        w.setValue(7, 1.5 * r);
                        w.setValue(8, LocalDateTime.of(2025, 6, 30, 12, 0, 0));
                        w.commitRow();
                    }
                }, format, new InsertSettings()).get()) {
                    List<GenericRecord> res = client.queryAll("SELECT count(), sum(length(text)) FROM " + TABLE);
                    System.out.println(name + ": written=" + response.getWrittenRows()
                            + " read back count=" + res.get(0).getLong(1) + " sum(length(text))=" + res.get(0).getLong(2));
                }
            } catch (Exception e) {
                Throwable c = e.getCause() != null ? e.getCause() : e;
                System.out.println(name + ": " + c.getClass().getSimpleName() + ": " + c.getMessage());
            }
        }
    
        public static void main(String[] args) throws Exception {
            try (Client client = new Client.Builder().addEndpoint(URL).setUsername("default").setPassword(PASSWORD).build()) {
                client.execute("DROP TABLE IF EXISTS " + TABLE).get().close();
                client.execute("CREATE TABLE " + TABLE + " (id UInt64, text String, note Nullable(String),"
                        + " ts DateTime64(3), tags Array(String), attrs Map(String, Int32), score Float64,"
                        + " created DateTime DEFAULT now(), id_mat UInt64 MATERIALIZED id * 2)"
                        + " ENGINE = MergeTree ORDER BY id").get().close();
            }
            run("1 row, default buffers", null, 1);
            run("1 row, buffers 458500", 7 * 65500, 1);
            run("1 row, buffers 512", 512, 1);
            run("10000 rows, default buffers", null, 10000);
            run("10000 rows, buffers 512", 512, 10000);
            try (Client client = new Client.Builder().addEndpoint(URL).setUsername("default").setPassword(PASSWORD).build()) {
                client.execute("DROP TABLE " + TABLE).get().close();
            }
        }
    }

    Output on main (8480ca001), ClickHouse 26.11.4.11:

    1 row, default buffers: written=1 read back count=1 sum(length(text))=501
    1 row, buffers 458500: written=1 read back count=1 sum(length(text))=501
    1 row, buffers 512: written=1 read back count=1 sum(length(text))=501
    10000 rows, default buffers: written=10000 read back count=10000 sum(length(text))=5038890
    10000 rows, buffers 512: written=10000 read back count=10000 sum(length(text))=5038890
    

    Automated triage by Polyglot AI. A maintainer makes the final decision.

  7. added
    data-types
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclientconnectivitydata-typesplanned_work

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions