[client-v2] An Error thrown while an insert writes its body shuts down the connection pool, so every later request of the Client fails
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 73/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- java
- Área
- backend, networking
Línea de trabajo
Start with HttpAPIClientHelper.createRequest in HttpAPIClientHelper.java, where the insert body write callback is passed to an EntityTemplate; the issue identifies this as the fix location. Check how the callback behaves when it throws an Error, then reproduce with the provided program against a local ClickHouse server. Done means the insert still propagates the Error, while a later request and ping() on the same Client succeed.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
When an Error (not an Exception) is thrown while client-v2 writes the body of an insert, the Client stays unusable: each later request fails with IllegalStateException: Connection pool shut down, and ping() returns false. Only a new Client works again.
The program below shows it on three entry points:
insert(table, DataStreamWriter, format, settings): the writer throwsAssertionError;insert(table, InputStream, format):read()of the stream throwsExceptionInInitializerError;insert(table, List<POJO>): the serialization throwsStackOverflowErrorfor aMapnested 10,000 levels deep in aDynamiccolumn.
A RuntimeException from the same writer fails only that insert. An Error that the caller throws while it reads a query response does not shut down the pool.
Root cause. Apache HttpClient 5 closes its connection manager when an Error passes through MainClientExec.execute (httpclient5 5.6.4, MainClientExec.java:185-187: connectionManager.close(CloseMode.IMMEDIATE)), and client-v2 writes the insert body inside that call: HttpAPIClientHelper.createRequest (HttpAPIClientHelper.java:903) gives the write callback to an EntityTemplate.
The fix is a wrapper of the write callback in HttpAPIClientHelper.createRequest. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: #3377 removes one trigger (a Dynamic value that contains itself, #3177), not this effect.
Steps to reproduce
- Start a ClickHouse server on
localhost:8123. - Run the program of "Code Example" with client-v2 from
main(java -cp <client-v2 classpath> Repro.java). - Each case makes one insert that fails, then runs
SELECT 1andping()on the sameClient.
Error Log or Exception StackTrace
writer throws AssertionError: insert threw java.lang.AssertionError
writer throws AssertionError: next request FAILED: java.lang.IllegalStateException: Connection pool shut down, ping() = false
InputStream.read throws ExceptionInInitializerError: insert threw java.lang.ExceptionInInitializerError
InputStream.read throws ExceptionInInitializerError: next request FAILED: java.lang.IllegalStateException: Connection pool shut down, ping() = false
POJO with a Map nested 10000 levels deep: insert threw java.lang.StackOverflowError
POJO with a Map nested 10000 levels deep: next request FAILED: java.lang.IllegalStateException: Connection pool shut down, ping() = false
contrast: writer throws IllegalStateException: insert threw com.clickhouse.client.api.ClickHouseException
contrast: writer throws IllegalStateException: next request OK, ping() = true
The Error passes through MainClientExec:
java.lang.AssertionError: boom
...
at com.clickhouse.client.api.Client.lambda$insert$2(Client.java:1878)
at org.apache.hc.core5.http.io.entity.EntityTemplate.writeTo(EntityTemplate.java:123)
...
at org.apache.hc.client5.http.impl.classic.MainClientExec.execute(MainClientExec.java:120)
...
at com.clickhouse.client.api.internal.HttpAPIClientHelper.doExecuteRequest(HttpAPIClientHelper.java:837)
The next request:
com.clickhouse.client.api.ClientException: Failed to get query response
at com.clickhouse.client.api.Client.queryAll(Client.java:2252)
Caused by: com.clickhouse.client.api.ClickHouseException: Query request failed (attempt: 1, duration: 0ms, queryId: null)
at com.clickhouse.client.api.internal.HttpAPIClientHelper.wrapException(HttpAPIClientHelper.java:1250)
Caused by: java.lang.IllegalStateException: Connection pool shut down
at org.apache.hc.core5.pool.LaxConnPool.lease(LaxConnPool.java:163)
at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.lease(PoolingHttpClientConnectionManager.java:366)
Expected Behaviour
Only the insert that throws fails, as with a RuntimeException: the caller gets the Error, and the next request on the same Client runs.
Code Example
Reproduction program (Java, 63 lines)
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.insert.InsertSettings;
import com.clickhouse.data.ClickHouseFormat;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
public class Repro {
public static class Row {
private int id; private Object v;
public Row() {}
public Row(int id, Object v) { this.id = id; this.v = v; }
public int getId() { return id; } public void setId(int id) { this.id = id; }
public Object getV() { return v; } public void setV(Object v) { this.v = v; }
}
static Client newClient() {
return new Client.Builder().addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("").build();
}
static void run(String label, Consumer<Client> failingInsert) {
try (Client client = newClient()) {
try {
failingInsert.accept(client);
} catch (Throwable t) {
System.out.println(label + ": insert threw " + t.getClass().getName());
}
try {
client.queryAll("SELECT 1");
System.out.println(label + ": next request OK, ping() = " + client.ping());
} catch (Exception e) {
Throwable root = e; while (root.getCause() != null) root = root.getCause();
System.out.println(label + ": next request FAILED: " + root + ", ping() = " + client.ping());
}
}
}
public static void main(String[] args) {
try (Client client = newClient()) {
client.queryAll("CREATE OR REPLACE TABLE t_s (id Int32) ENGINE = Memory");
client.queryAll("CREATE OR REPLACE TABLE t_d (id Int32, v Dynamic) ENGINE = MergeTree ORDER BY id");
}
run("writer throws AssertionError", c -> c.insert("t_s",
out -> { throw new AssertionError("boom"); },
ClickHouseFormat.RowBinary, new InsertSettings()).join());
run("InputStream.read throws ExceptionInInitializerError", c -> c.insert("t_s", new InputStream() {
@Override public int read() { throw new ExceptionInInitializerError("boom"); }
}, ClickHouseFormat.RowBinary).join());
run("POJO with a Map nested 10000 levels deep", c -> {
c.register(Row.class, c.getTableSchema("t_d"));
Object v = "leaf";
for (int i = 0; i < 10_000; i++) { Map<String, Object> m = new HashMap<>(); m.put("k", v); v = m; }
c.insert("t_d", Collections.singletonList(new Row(1, v))).join();
});
run("contrast: writer throws IllegalStateException", c -> c.insert("t_s",
out -> { throw new IllegalStateException("boom"); },
ClickHouseFormat.RowBinary, new InsertSettings()).join());
}
}
Configuration
Client Configuration
new Client.Builder().addEndpoint("http://localhost:8123").setUsername("default").setPassword("").build()
Environment
- Cloud
- Client version: client-v2 from
main8480ca001 (0.12.0-rc1-SNAPSHOT), httpclient5 5.6.4 - Language version: Java 17.0.21
- OS: Linux
ClickHouse Server
- ClickHouse Server version: 26.11.2.4
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: in the program- Sample data for all these tables: none
Classification: impact: Stability · area: Connectivity (connection pool)
Found by automated analysis (Polyglot AI) while working on #3177. Verified against a live server.
- Lenguaje dominante
- Java
- Estrellas
- 1.6k
- Forks
- 657
- Merge medio
- 2 d 6 h
- PR fusionados (30 d)
- 36
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
ClickHouse/clickhouse-java#3464 ·
Los mantenedores suelen responder en 1 día
-
tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ClickHouse/clickhouse-java#3452 ·
Los mantenedores suelen responder en 1 día
-
bug jdbc performance queries sql-parser
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
ClickHouse/clickhouse-java#3451 ·
Los mantenedores suelen responder en 1 día
-
bug jdbc legacy queries
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
ClickHouse/clickhouse-java#3444 ·
Los mantenedores suelen responder en 1 día
-
api-diagnostics bug client jdbc
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ClickHouse/clickhouse-java#3439 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de ClickHouse/clickhouse-java
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
quelea-projection/Quelea#749 ·
Los mantenedores suelen responder en 1 día
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
erkamyaman/rust-anything#963 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 76/100
-
Deferred
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Sanne/incus-spawn#2768 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
morluto/rea#15041 · 1 comentario ·
Los mantenedores suelen responder en 1 día