Repository navigation
Description
Description
Client.insert reuses requestSettings.getQueryId() across every retry attempt. After NoHttpResponseException (retried by default via ClientFaultCause.NoHttpResponse) the first request may already have reached the server and still be executing. The second attempt is then rejected with Code: 216 QUERY_WITH_SAME_ID_IS_ALREADY_RUNNING, which is not retryable, so a transient transport fault becomes a hard failure.
#1721 introduced the retry and noted that "not every request may be retried safely". This is that case.
Steps to reproduce
client.insert(table, data, format, settings)with default retry settings through a proxy or load balancer.- The proxy closes the keep-alive connection after forwarding the request, while the server is still executing the insert (
async_insert=1, wait_for_async_insert=1makes the window at least the busy timeout). - The client gets
NoHttpResponseException, logsRetrying., and resends with the same query id. The server answers 216.
Error Log or Exception StackTrace
WARN Retrying. (com.clickhouse.client.api.Client)
org.apache.hc.core5.http.NoHttpResponseException: <host>:8443 failed to respond
at org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:333)
...
at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:453)
at com.clickhouse.client.api.Client.lambda$insert$3(Client.java:1474)
at com.clickhouse.client.api.Client.runAsyncOperation(Client.java:2012)
at com.clickhouse.client.api.Client.insert(Client.java:1518)
com.clickhouse.client.api.ServerException: Code: 216. DB::Exception: Query with id = b266240e-d406-4874-ba3b-cd1b0bd969f8 is already running. (QUERY_WITH_SAME_ID_IS_ALREADY_RUNNING) (version 26.4.1.2359 (official build))
at com.clickhouse.client.api.internal.HttpAPIClientHelper.readError(HttpAPIClientHelper.java:403)
at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:467)
at com.clickhouse.client.api.Client.lambda$insert$3(Client.java:1474)
at com.clickhouse.client.api.Client.runAsyncOperation(Client.java:2012)
at com.clickhouse.client.api.Client.insert(Client.java:1518)
at com.clickhouse.client.api.Client.insert(Client.java:1408)
Expected Behaviour
A retry after a fault where the first request may have been delivered does not collide with its own earlier attempt. Either the retry uses a fresh query id, or the client does not retry once the request body has been sent.
Configuration
Client Configuration
Defaults: retry=3, retryOnFailures = [NoHttpResponse, ConnectTimeout, ConnectionRequestTimeout, ServerRetryable]. Caller sets queryId and insert_deduplication_token per insert (clickhouse-kafka-connect v1.6.0).
Environment
- Cloud
- Client version: client-v2 0.9.5 (insert loop unchanged on 0.9.6, 0.10.0 and
main) - Language version: Java 21.0.10
- OS: Linux
ClickHouse Server
- ClickHouse Server version: 26.4.1 and 26.6.1
- Non-default settings:
async_insert=1, wait_for_async_insert=1, async_insert_busy_timeout_ms=200
Related: #1529 (same code, different cause). Downstream: ClickHouse/clickhouse-kafka-connect#847.
Activity
chernser commentedon Oct 14, 2026
thank you for reporting this @billykern !
I will look into it.
billykern commentedon Oct 15, 2026
Thank you @chernser 🙏
polyglotAI-bot commentedon Nov 27, 2026
Recommendation: Keep open — fix needed
No open PR. The fix needs a maintainer decision: what the client does when it retries an insert that the server can already have received (the issue gives two options).
main: Reproduced on main — the retry sends the same query id, the server answers 216, and the first attempt stores the row.docs/features.md:37), whichdocs/ai-review.mdlists as high-risk.Analysis:
Client.java:1871reads the query id once, before the retry loop, and every attempt sends the same settings (Client.java:1876);HttpAPIClientHelper.java:1185retries aNoHttpResponseExceptionby default, also when the server got the request. The POJO insert (Client.java:1627) andquery(Client.java:2028) reuse the query id the same way. A query id is sent only when the caller sets one or asetQueryIdGeneratorsupplier (Client.java:1857).Reproduction: complete program and output
Changed from the issue's steps: a proxy in the program forwards the first INSERT and then closes the connection with no response;
async_insert_busy_timeout_ms=3000keeps the first attempt running.Output on
main(8480ca001), ClickHouse 26.11.2.4:Automated triage by Polyglot AI. A maintainer makes the final decision.