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
ClickHouse java client - reusing same instance of ClickHouseClient gives execution timeout after 10 inserts #1668
clientModule: the client (client-v2; with legacy: the v1 client)connectivityArea: connection, TLS, pool, timeouts, cancellation, transport, compressionenhancementlegacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problemplanned_workWork that is planned for nearest release. Good to take
This code only inserts 10 records, after that I get an Code: 159. Execution timed out Exception
I have already tried to change and add some ClickHouseClientOptions but I always get the same behaviour. How can I reuse the same client connections in clickhouse using java client?
@occunha thank you for reporting the issue. I suspect it happens because some internal timer is not stopped and continues because you are reusing the request object.
I will try to replicate the issue.
Good day,
The root cause of the problem is that response object is not closed before sending a new request. I've reproduced the problem and here is my fixed version:
Recommendation: Keep open — maintainer decision
The v1 client keeps a pool connection for each ClickHouseResponse that the caller does not close, also for an INSERT. Decide whether the v1 client must release that connection by itself; client-v2 Client.execute() already closes its response.
Status on main: Not supported on main — on 8480ca001, ClickHouse 26.11.4.11, the issue's loop (with a 2-column table) fails at the 11th insert with Code: 159. Execution timed out after 30 s. With the response closed, 20 of 20 inserts succeed. client-v2 execute() with no close: 20 of 20.
Breaking change: No — can be done without a break.
Analysis:executeAndWait() gives a ClickHouseResponse that holds its pool connection until close(). The v1 pool allows 10 connections per host (max_open_connections, clickhouse-http-client/…/config/ClickHouseHttpOption.java:39), so the 11th request waits until socket_timeout (30 s, clickhouse-client/…/config/ClickHouseClientOption.java:289) and fails with Code 159. In client-v2, CommandResponse closes the response in its constructor (client-v2/…/api/command/CommandResponse.java:17).
Automated triage by Polyglot AI. A maintainer makes the final decision.
clientModule: the client (client-v2; with legacy: the v1 client)connectivityArea: connection, TLS, pool, timeouts, cancellation, transport, compressionenhancementlegacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problemplanned_workWork that is planned for nearest release. Good to take
Activity
den-crane commentedon Jun 3, 2024
Why do you use
.format? and why do useCustomSeparated?occunha commentedon Jun 3, 2024
@den-crane That was an experience, But I get the exact same behaviour, with or without that
shilaidun commentedon Jun 5, 2024
#1538 same problem?
chernser commentedon Jun 10, 2024
@occunha thank you for reporting the issue. I suspect it happens because some internal timer is not stopped and continues because you are reusing the request object.
I will try to replicate the issue.
chernser commentedon Jun 10, 2024
Thank @shilaidun! It is a good idea to check it. Will do.
chernser commentedon Jun 11, 2024
Good day,
The root cause of the problem is that response object is not closed before sending a new request. I've reproduced the problem and here is my fixed version:
The class
ClickHouseResponseisClosableand can be used intryblock:So object
respwill be closed by existing from the block.I see the problem is that query do not expect reading data from server and it would be good to make the client close response in such cases.
mshustov commentedon Nov 29, 2024
@chernser hasn't it been fixed for v2?
chernser commentedon Nov 14, 2025
@mshustov
It is a application error. We may be can improve it by wrapping future and closing connection on timeout.
chernser commentedon Nov 14, 2025
relates #1619
polyglotAI-bot commentedon Nov 28, 2026
Recommendation: Keep open — maintainer decision
The v1 client keeps a pool connection for each
ClickHouseResponsethat the caller does not close, also for anINSERT. Decide whether the v1 client must release that connection by itself; client-v2Client.execute()already closes its response.main: Not supported on main — on8480ca001, ClickHouse 26.11.4.11, the issue's loop (with a 2-column table) fails at the 11th insert withCode: 159. Execution timed outafter 30 s. With the response closed, 20 of 20 inserts succeed. client-v2execute()with no close: 20 of 20.getRowsUpdated, closed. Related: [client-v2] Resource release #2649 — guard rails for unclosed client-v2 responses.Analysis:
executeAndWait()gives aClickHouseResponsethat holds its pool connection untilclose(). The v1 pool allows 10 connections per host (max_open_connections,clickhouse-http-client/…/config/ClickHouseHttpOption.java:39), so the 11th request waits untilsocket_timeout(30 s,clickhouse-client/…/config/ClickHouseClientOption.java:289) and fails with Code 159. In client-v2,CommandResponsecloses the response in its constructor (client-v2/…/api/command/CommandResponse.java:17).Automated triage by Polyglot AI. A maintainer makes the final decision.