Skip to content

java.sql.BatchUpdateException: Broken pipe (Write failed), server ClickHouseNode #1620

Open

Description

@libob111

I write a Scala code using Spark to push data from a Hive table to ClickHouse. When I use the clickhouse-jdbc version 0.6.0, I set the following parameters.

      properties.setProperty("http_connection_provider", HttpConnectionProvider.APACHE_HTTP_CLIENT.name());
      properties.setProperty("socket_ip_tos", "32"); 

There is no problem when predicting 5kw data , but an exception is thrown when it becomes 5e data. threw an error as follows:

24/04/25 15:05:53 [task-result-getter-0] WARN TaskSetManager: Lost task 67.0 in stage 1.0 (TID 690, 11.11.10.76, executor 60): java.sql.BatchUpdateException: Broken pipe (Write failed), server ClickHouseNode [uri=http://sq02-ch-000119-clickhouse-17-1.local:8623/default, options={db=ge_order,socket_ip_tos=32,http_connection_provider=APACHE_HTTP_CLIENT}]@290467083
at com.clickhouse.jdbc.SqlExceptionUtils.batchUpdateError(SqlExceptionUtils.java:107)
at com.clickhouse.jdbc.internal.InputBasedPreparedStatement.executeAny(InputBasedPreparedStatement.java:154)
at com.clickhouse.jdbc.internal.AbstractPreparedStatement.executeLargeBatch(AbstractPreparedStatement.java:85)
at com.clickhouse.jdbc.internal.ClickHouseStatementImpl.executeBatch(ClickHouseStatementImpl.java:752)
at com.jd.clickhouse.spark.DataFrameExt$$anonfun$13$$anonfun$apply$23.apply(DataFrameExt.scala:513)
at com.jd.clickhouse.spark.DataFrameExt$$anonfun$13$$anonfun$apply$23.apply(DataFrameExt.scala:467)

When I adjust it to:

properties.setProperty("http_connection_provider", HttpConnectionProvider.HTTP_URL_CONNECTION.name())

threw an error as follows:

WARN TaskSetManager: Lost task 91.0 in stage 1.0 (TID 717, 10.198.62.132, executor 116): java.sql.BatchUpdateException: Error writing request body to server, server ClickHouseNode [uri=http://sq02-ch-000119-clickhouse-23-1.local:8623/default, options={db=ge_order,socket_ip_tos=32,http_connection_provider=HTTP_URL_CONNECTION}]@665046067
at com.clickhouse.jdbc.SqlExceptionUtils.batchUpdateError(SqlExceptionUtils.java:107)
at com.clickhouse.jdbc.internal.InputBasedPreparedStatement.executeAny(InputBasedPreparedStatement.java:154)
at com.clickhouse.jdbc.internal.AbstractPreparedStatement.executeLargeBatch(AbstractPreparedStatement.java:85)
at com.clickhouse.jdbc.internal.ClickHouseStatementImpl.executeBatch(ClickHouseStatementImpl.java:752)
at com.jd.clickhouse.spark.DataFrameExt$$anonfun$13$$anonfun$apply$23.apply(DataFrameExt.scala:513)

When I use the ru.yandex.clickhouse 0.1.34 ,The same problem will not occur.

The versions of ClickHouse, Spark version are all consistent.

Activity

  1. chernser commented on Apr 26, 2024

    @chernser
    Contributor

    Good day, @libob111 ! Thank you for reporting the issue.
    Few questions:

    1. Is CH DB a cloud or on-premise? Who manages it?
    2. What are other settings?
    3. I'm not very familiar with "5kw data" and "5e data" definitions. Would you please explain a bit or give some reference?

    Thanks!

  2. libob111 commented on May 7, 2024

    @libob111
    Author

    Good day, @libob111 ! Thank you for reporting the issue. Few questions:

    1. Is CH DB a cloud or on-premise? Who manages it?
    2. What are other settings?
    3. I'm not very familiar with "5kw data" and "5e data" definitions. Would you please explain a bit or give some reference?

    Thanks!

    Thank you for your response.
    1、CH DB is deployed as a container by our company's DevOps team.
    2、Cluster information, Spark versions are completely consistent, only the parameters and jdbc version mentioned earlier are different.
    3、Sorry, that was my mistake."5kw data" and "5e data" represent data sizes of 50 million rows and 500 million rows respectively.

  3. bysph commented on May 22, 2024

    @bysph

    I encounter the same issue when I have 121 concurrent connections and insert 500,000 records per batch. The ClickHouse server's CPU and network card are operating at normal levels.

  4. chernser commented on May 22, 2024

    @chernser
    Contributor

    @libob111 @bysph Thank you for the response! We will look into the problem.

  5. mzitnik commented on May 22, 2024

    @mzitnik
    Contributor

    Hi @libob111 @bysph
    It is something that needs to be fixed, but have you tried https://github.com/housepower/spark-clickhouse-connector

  6. mzitnik commented on May 22, 2024

    @mzitnik
    Contributor

    What Apache Spark version are you using, and how many partitions do you have?

  7. libob111 commented on May 22, 2024

    @libob111
    Author

    1、Apache Spark version:2.4.7
    2、In this scenario, I am writing approximately 500 million records into a single partition. ClickHouse has 22 shards, and the data is evenly divided into 88 tasks for writing. Each shard has 4 tasks writing to it simultaneously, with the batch size for each write set to 100,000.

  8. added
    connectivity
    on Jan 10, 2025
  9. hotstar-xia commented on May 16, 2025

    @hotstar-xia

    Encountered similar problems when using df.write(). The inserted data is not complete. @chernser Is there any workaround or mitigations?

    • Client Configuration
      ClickHouse version: 25.4.3.22
    • Environment
      clickhouse-jdbc: 0.6.0-patch3
      clickhouse-data: 0.8.5
      Spark version: Databricks Runtime 12.2 LTS (Apache Spark 3.3.2, Scala 2.12)
      Cluster type: Single-node
  10. github-actions commented on May 17, 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!

  11. polyglotAI-bot commented on Nov 28, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — needs info from the reporter
    Broken pipe means that the server or a component between Spark and the server closed the connection while the driver sent the batch. The report does not show which one, or why. Ask the reporter for the items in the Analysis.

    • Category: Bug
    • Classification: impact: none · area: Connectivity (batch upload)
    • Status on main: Needs info — a 3,000,000-row batch that the server rejects at its first block gives the server's Code 469 error in jdbc-v2 and in the v1 driver, not Broken pipe.
    • Breaking change: No
    • Duplicates / related: Related: BatchUpdateException during inserts with jdbc driver #1444 — v1 batch inserts through a load balancer fail with "Unexpected end of file".

    Analysis: When the server rejects an upload, both drivers report the server's error (run below), so a Broken pipe with no server message points to a connection that another component closed. The report uses port 8623, not the default 8123. Missing: whether a proxy or load balancer is in front of the server, the server log (and that component's log) at the time of the error, the full stack trace with its cause, the server version, and whether the error occurs with jdbc-v2 (the default driver since 0.8.0; the report uses the 0.6.0 v1 driver).

    Reproduction: complete program and output
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.util.Properties;
    
    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 void batch(String driver, String jdbcUrl, int rows) {
            Properties props = new Properties();
            props.setProperty("user", "default");
            props.setProperty("password", PASSWORD);
            long t0 = System.nanoTime();
            try (Connection conn = DriverManager.getConnection(jdbcUrl, props);
                 PreparedStatement ps = conn.prepareStatement("INSERT INTO issue1620 (id, s) VALUES (?, ?)")) {
                for (int i = 0; i < rows; i++) {
                    ps.setLong(1, i);
                    ps.setString(2, "value-" + i);
                    ps.addBatch();
                }
                ps.executeBatch();
                System.out.printf("%s, %d rows: ok%n", driver, rows);
            } catch (Exception e) {
                String msg = String.valueOf(e.getMessage());
                System.out.printf("%s, %d rows: %s: %s (after %d ms)%n", driver, rows, e.getClass().getName(),
                        msg.length() > 160 ? msg.substring(0, 160) + "…" : msg, (System.nanoTime() - t0) / 1_000_000);
            }
        }
    
        public static void main(String[] args) throws Exception {
            String base = "jdbc:clickhouse:" + URL.replaceFirst("^https?:", "") + "/default";
            Properties props = new Properties();
            props.setProperty("user", "default");
            props.setProperty("password", PASSWORD);
            try (Connection conn = DriverManager.getConnection(base, props); Statement st = conn.createStatement()) {
                st.execute("DROP TABLE IF EXISTS issue1620");
                // the server rejects each block: every row violates the constraint
                st.execute("CREATE TABLE issue1620 (id Int64, s String, CONSTRAINT neg CHECK id < 0) ENGINE = MergeTree ORDER BY id");
            }
            batch("jdbc-v2", base, 3_000_000);
            // v1 driver; compress=0: v1 compressed reads fail on server 26.9+ (clickhouse-java#3107).
            // After this URL, ClickHouseDriver keeps the v1 driver for every URL (clickhouse-java#3459), so v1 runs last.
            String v1 = base + "?clickhouse.jdbc.v1=true&compress=0";
            batch("v1 driver", v1, 3_000_000);
            try (Connection conn = DriverManager.getConnection(v1, props); Statement st = conn.createStatement()) {
                st.execute("DROP TABLE issue1620");
            }
        }
    }

    Output on main (8480ca001), ClickHouse 26.11.4.11:

    jdbc-v2, 3000000 rows: java.sql.SQLException: Code: 469. DB::Exception: Constraint `neg` for table default.issue1620 (…) is violated at row 1. Expression: (id < 0). Column… (after 1343 ms)
    v1 driver, 3000000 rows: java.sql.BatchUpdateException: Code: 469. DB::Exception: Constraint `neg` for table default.issue1620 (…) is violated at row 1. Expression: (id < 0). Column… (after 413 ms)
    

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

  12. added
    jdbc
    needs-info
    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

    bugconnectivityjdbcneeds-info

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions