You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BatchUpdateException during inserts with jdbc driver #1444
bugclientModule: the client (client-v2; with legacy: the v1 client)connectivityArea: connection, TLS, pool, timeouts, cancellation, transport, compressioninvestigatingInvestigation of a root cause is on goinglegacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problem
Hello. I have an issue with connection to Clickhouse with the driver (version 0.4.6).
The problems with Inserts. There is an exception:
java.sql.BatchUpdateException: Unexpected end of file from server, server ClickHouseNode [uri=http://clickhouse.dwh.staging.com:8123/default]@-971229636 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)
I've tried change some timeouts on ClickHouse side, I've tested with several versions of driver. Still have this kind of problems.
Inserts 10k-100k
ch version - 23.3.8
driver - 0.4.6
It's not a blocker for me, because with retries the data is inserted but have at least 10 exceptions per hour.
Could you please give me some advice?
Hi @stasDomb, thanks for reporting the issue. Is there any clue on server side? Are you using proxy between the client and server?
Hello, thank you for the answer. I don't see anything interesting on Server side, no errors etc.
We are using ClickHouse operator and load balancer there
Hello, after updating to the version 5.0.0 the previous error was vanished, but a new one was appeared: java.sql.BatchUpdateException: The target server failed to respond, server ClickHouseNode [uri=http://hostname:8123/default]@1702260979 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)
Hello! Do you have any updates on this issue? I faced with the similar exception:
Caused by: java.sql.BatchUpdateException: The target server failed to respond, server ClickHouseNode [uri=http://clickhouse:8123/test]@-628742641
at com.clickhouse.jdbc.SqlExceptionUtils.batchUpdateError(SqlExceptionUtils.java:107)
at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeAny(SqlBasedPreparedStatement.java:219)
at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeQuery(SqlBasedPreparedStatement.java:246)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:722)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:648)
... 207 more
I tried setting connectionTestQuery & validationTimeout (as it was mentioned here #290), but it did not work for me. Apparently, the exception originates from the HTTP client.
I also took a look at HTTP tracing & TCP dumps. There is an "end of stream" record in the HTTP trace right after the request with SQL:
I didn't find any records on the ClickHouse server side corresponding to the request Id or any other clues.
The TCP dumps look like the server initiates the connection closing (after 3sec timeout), but the client still tries using it (I am not sure here)
I tried sending the same request that the driver/HTTP client sends from the same machine, but using curl instead. And everything worked fine, I got 200 Ok with the requested data. But it does not work when I am using jdbc driver from the application.
Finally, I found this PR #760 which seems to address the relevant issue. This PR introduces the new setting validateAfterInactivityMillis, but I can't find the corresponding one in the latest version of the driver (0.5.0). The mentioned PR was made for the older version which has ru.yandex.* packages naming. @zhicwu Could you help me, please? Is there any setting in 0.5.0 version that works the same way? Or any other solution for this issue?
Hello! Do you have any updates on this issue? I faced with the similar exception:
Caused by: java.sql.BatchUpdateException: The target server failed to respond, server ClickHouseNode [uri=http://clickhouse:8123/test]@-628742641
at com.clickhouse.jdbc.SqlExceptionUtils.batchUpdateError(SqlExceptionUtils.java:107)
at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeAny(SqlBasedPreparedStatement.java:219)
at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeQuery(SqlBasedPreparedStatement.java:246)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:722)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:648)
... 207 more
I tried setting connectionTestQuery & validationTimeout (as it was mentioned here #290), but it did not work for me. Apparently, the exception originates from the HTTP client.
I also took a look at HTTP tracing & TCP dumps. There is an "end of stream" record in the HTTP trace right after the request with SQL:
I didn't find any records on the ClickHouse server side corresponding to the request Id or any other clues.
The TCP dumps look like the server initiates the connection closing (after 3sec timeout), but the client still tries using it (I am not sure here)
I tried sending the same request that the driver/HTTP client sends from the same machine, but using curl instead. And everything worked fine, I got 200 Ok with the requested data. But it does not work when I am using jdbc driver from the application.
Finally, I found this PR #760 which seems to address the relevant issue. This PR introduces the new setting validateAfterInactivityMillis, but I can't find the corresponding one in the latest version of the driver (0.5.0). The mentioned PR was made for the older version which has ru.yandex.* packages naming. @zhicwu Could you help me, please? Is there any setting in 0.5.0 version that works the same way? Or any other solution for this issue?
My use case is Trino(435) connecting to Clickhouse(21.11.10.1).
I upgraded to 0.6.0 but still had this problem:
Caused by: java.sql.BatchUpdateException: The target server failed to respond, server ClickHouseNode [uri=http://haproxy:8123/default, options={socket_timeout=120000,externalDatabase=false,server_time_zone=Asia/Shanghai,server_version=21.11.10.1,use_binary_string=true}]@1936783272
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 io.opentelemetry.instrumentation.jdbc.internal.OpenTelemetryStatement.wrapCall(OpenTelemetryStatement.java:294)
at io.opentelemetry.instrumentation.jdbc.internal.OpenTelemetryStatement.executeBatch(OpenTelemetryStatement.java:106)
at io.trino.plugin.jdbc.JdbcPageSink.appendPage(JdbcPageSink.java:153)
... 13 more
The target server failed to respond, server ClickHouseNode
Client keepalive.timeout=3 / Server keepalive.timeout=3
1 Client successfully executes some query.
2 Client http connection is idle for 2.999999 seconds.
3 Client checks "Am i ildle less than 3 seconds?" - I am. 2.999999<3.0
4 Server closes http because 3 seconds pass.
5 Client sends a new request to Clickhouse server.
6 Server responses with a disconnect.
Server keepalive.timeout should be significantly bigger than Client keepalive.timeout.
Webbrowsers have keepalive = 30, webservers have keepalive = 60
Server keep_alive_timeout = 3
However, adjusting the keep_alive_timeout parameter for a production cluster is a difficult task. Is there any good idea?
I also see the com.clickhouse.client.ClickHouseException: HTTP request failed: Broken pipe, server ClickHouseNode. with CH v.23.8.2.7 and java drivers v 0.5.0, and 0.6.0p4.
We use HTTP async writes, with async_insert and wait_for_async_insert set to 1. keep_alive in config.xml is default/3s and there is nothing fancy in how the mutation is set. Neither there is anything interesting in clickhouse-server.log or clickhouse-server.err.log
This error seems to be more likely to happen when the writes/load is spiking. The problem is that it happens about once or twice a day and I'm not sure how to catch the issue at the correct time to setup the packet capture. Leaving packet capture for 24 hours seems not feasible.
For the records, I tried variety of driver configuration options, perhaps except writing a custom socket.
Please, advise on how to troubleshoot or resolve the issue.
Any update on this issue? We're also receiving the error when reading data from Clickhouse through a Java Client application
Caused by: java.sql.BatchUpdateException: The target server failed to respond
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:819)
We have been experiencing it as well. Our work-around was to increase the batch sizes and reduce the parallelism as much as possible to maintain the desired performance.
Recommendation: Keep open — maintainer decision
The v1 stack fails a request on a pooled connection that a proxy closed while it was idle. jdbc-v2, the default driver since 0.8.0, retries the request and succeeds. Decide whether the v1 stack gets a fix, or the issue closes with jdbc-v2 as the answer.
Category: Bug
Classification: impact: none · area: Connectivity (stale pooled connections)
Status on main: Reproduced on main — through a proxy that closes idle connections after 1 s, the v1 driver fails the next batch with Broken pipe. jdbc-v2 succeeds.
Breaking change: No — can be done without a break.
Workaround: Use jdbc-v2 (the default driver of clickhouse-jdbc since 0.8.0); in the run, it sends the batch again on a new connection.
Analysis: The v1 HTTP client checks a pooled connection only after 5000 ms of inactivity (ahc_validate_after_inactivity, clickhouse-http-client/src/main/java/com/clickhouse/client/http/config/ClickHouseHttpOption.java:74), so it sends the request on a connection that the proxy closed before. ahc_retry_on_failure=true does not help in the run: it retries only NoHttpResponseException and ConnectionClosedException (ApacheHttpConnectionImpl.java:311), and the Broken pipe goes to the IOException branch (line 317). client-v2 and jdbc-v2 retry NoHttpResponse by default (client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java:229).
bugclientModule: the client (client-v2; with legacy: the v1 client)connectivityArea: connection, TLS, pool, timeouts, cancellation, transport, compressioninvestigatingInvestigation of a root cause is on goinglegacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problem
Activity
[-]BatchUpdateException during inserts[/-][+]BatchUpdateException during inserts with jdbc driver[/+]zhicwu commentedon Sep 7, 2023
Hi @stasDomb, thanks for reporting the issue. Is there any clue on server side? Are you using proxy between the client and server?
stasDomb commentedon Sep 11, 2023
Hello, thank you for the answer. I don't see anything interesting on Server side, no errors etc.
We are using ClickHouse operator and load balancer there
stasDomb commentedon Oct 26, 2023
Hello, after updating to the version 5.0.0 the previous error was vanished, but a new one was appeared:
java.sql.BatchUpdateException: The target server failed to respond, server ClickHouseNode [uri=http://hostname:8123/default]@1702260979 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)eremeykin commentedon Dec 8, 2023
Hello! Do you have any updates on this issue? I faced with the similar exception:
client:
com.clickhouse:clickhouse-jdbc:0.5.0+ HikariCP 5.0.1 + Spring Boot 3.1.4server: 23.1.7.30
I tried setting
connectionTestQuery&validationTimeout(as it was mentioned here #290), but it did not work for me. Apparently, the exception originates from the HTTP client.I also took a look at HTTP tracing & TCP dumps. There is an
"end of stream"record in the HTTP trace right after the request with SQL:I didn't find any records on the ClickHouse server side corresponding to the request Id or any other clues.
The TCP dumps look like the server initiates the connection closing (after 3sec timeout), but the client still tries using it (I am not sure here)

I tried sending the same request that the driver/HTTP client sends from the same machine, but using
curlinstead. And everything worked fine, I got 200 Ok with the requested data. But it does not work when I am using jdbc driver from the application.Finally, I found this PR #760 which seems to address the relevant issue. This PR introduces the new setting
validateAfterInactivityMillis, but I can't find the corresponding one in the latest version of the driver (0.5.0). The mentioned PR was made for the older version which hasru.yandex.*packages naming. @zhicwu Could you help me, please? Is there any setting in 0.5.0 version that works the same way? Or any other solution for this issue?stasDomb commentedon Dec 12, 2023
Unfortunately, I still have this kind of problem
janson653 commentedon Jan 9, 2024
Hello guys, I meet the same issue, any update?
bairamovazat commentedon Feb 1, 2024
Hi!
I updated the library version to 0.6.0 and everything worked.
Maybe it will help someone else too.
akenO8 commentedon Feb 27, 2024
My use case is Trino(435) connecting to Clickhouse(21.11.10.1).
I upgraded to 0.6.0 but still had this problem:
den-crane commentedon Feb 27, 2024
Client keepalive.timeout=3 / Server keepalive.timeout=3
1 Client successfully executes some query.
2 Client http connection is idle for 2.999999 seconds.
3 Client checks "Am i ildle less than 3 seconds?" - I am. 2.999999<3.0
4 Server closes http because 3 seconds pass.
5 Client sends a new request to Clickhouse server.
6 Server responses with a disconnect.
Server keepalive.timeout should be significantly bigger than Client keepalive.timeout.
Webbrowsers have keepalive = 30, webservers have keepalive = 60
akenO8 commentedon Apr 7, 2024
Server keep_alive_timeout = 3
However, adjusting the keep_alive_timeout parameter for a production cluster is a difficult task. Is there any good idea?
JeasGo commentedon Apr 23, 2024
Hi , I meet the same issue, I have updated to version 0.6.0 but it doesn't work, please tell me how to solve it
vera-dobryanskaya commentedon May 15, 2024
I also see the
com.clickhouse.client.ClickHouseException: HTTP request failed: Broken pipe, server ClickHouseNode. with CH v.23.8.2.7 and java drivers v 0.5.0, and 0.6.0p4.We use HTTP async writes, with
async_insertandwait_for_async_insertset to 1.keep_aliveinconfig.xmlis default/3s and there is nothing fancy in how the mutation is set. Neither there is anything interesting in clickhouse-server.log or clickhouse-server.err.logThis error seems to be more likely to happen when the writes/load is spiking. The problem is that it happens about once or twice a day and I'm not sure how to catch the issue at the correct time to setup the packet capture. Leaving packet capture for 24 hours seems not feasible.
For the records, I tried variety of driver configuration options, perhaps except writing a custom socket.
Please, advise on how to troubleshoot or resolve the issue.
9 remaining items
weipengfei-sj commentedon Nov 15, 2024
Any update on this issue? We're also receiving the error when reading data from Clickhouse through a Java Client application
Caused by: java.sql.BatchUpdateException: The target server failed to respond
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:819)
acoj1993 commentedon Nov 15, 2024
We have been experiencing it as well. Our work-around was to increase the batch sizes and reduce the parallelism as much as possible to maintain the desired performance.
joeyvmason commentedon Nov 19, 2024
Experiencing this as well
filimonov commentedon Nov 25, 2025
See https://gist.github.com/filimonov/6d352ce19d6fa117757ccd068f7d4b97
chernser commentedon Nov 25, 2025
@filimonov
Thank you for this deep analysis!
polyglotAI-bot commentedon Nov 28, 2026
Recommendation: Keep open — maintainer decision
The v1 stack fails a request on a pooled connection that a proxy closed while it was idle. jdbc-v2, the default driver since 0.8.0, retries the request and succeeds. Decide whether the v1 stack gets a fix, or the issue closes with jdbc-v2 as the answer.
main: Reproduced on main — through a proxy that closes idle connections after 1 s, the v1 driver fails the next batch withBroken pipe. jdbc-v2 succeeds.Broken pipewhile a large batch is sent, not after idle time. Related: [client-v2, jdbc-v2] The default retry after NoHttpResponseException runs a write statement twice and reports success #3455 — the default v2 retry can run a write statement twice.clickhouse-jdbcsince 0.8.0); in the run, it sends the batch again on a new connection.Analysis: The v1 HTTP client checks a pooled connection only after 5000 ms of inactivity (
ahc_validate_after_inactivity,clickhouse-http-client/src/main/java/com/clickhouse/client/http/config/ClickHouseHttpOption.java:74), so it sends the request on a connection that the proxy closed before.ahc_retry_on_failure=truedoes not help in the run: it retries onlyNoHttpResponseExceptionandConnectionClosedException(ApacheHttpConnectionImpl.java:311), and theBroken pipegoes to theIOExceptionbranch (line 317). client-v2 and jdbc-v2 retryNoHttpResponseby default (client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java:229).Reproduction: complete program and output
Output on
main(8480ca001), ClickHouse 26.11.4.11:Automated triage by Polyglot AI. A maintainer makes the final decision.