[client-v1] ClickHouseException.getErrorCode() takes the code from a data row when a compressed query fails after rows
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Read ApacheHttpConnectionImpl.checkResponse and HttpUrlConnectionImpl for client-v1, then compare ClickHouseException.extractErrorCode and ClickHouseHttpConnection.parseErrorFromException; the report also identifies HttpAPIClientHelper.readClickHouseError in client-v2 and related issue #3439. Start by tracing how response headers and body text determine the error code and message. Reproduce with the supplied Java example; done when failures after rows report server code 395 and a message beginning with the server exception.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
When a query fails during execution and the response is compressed, the server answers HTTP 500 with the rows that it already produced, then the exception text. If a row before the exception contains Code: <N>, client-v1 throws a ClickHouseException whose getErrorCode() is the <N> of the row, not the server's code. The message also starts in the row data. The same defect was reported for clickhouse-js in https://github.com/ClickHouse/clickhouse-js/issues/1175.
Values of this form are normal, for example in SELECT exception FROM system.query_log.
Scope seen in the run (3 of 3 runs):
- client-v1 over HTTP, with the default
compress_algorithm(LZ4,compress=1) and with GZIP, ZSTD, BROTLI and DEFLATE; formats JSONEachRow and RowBinaryWithNamesAndTypes. - client-v2 takes the code from the
X-ClickHouse-Exception-Codeheader, so its code is correct. Its message starts in the row data only when a row contains the same code text (Code: 395.), with and withoutuseHttpCompression(true).
Steps to reproduce
- Start ClickHouse server 26.10 with default settings.
- Run the code example (set
CLICKHOUSE_URLandCLICKHOUSE_PASSWORDas needed). Each query fails withthrowIfafter the server produced some rows. - Compare each code and message with the server's code 395.
Error Log or Exception StackTrace
v1 LZ4: code 60, message Code: 60. DB::Exception: Unknown table x.
v1 GZIP: code 60, message {"exception":"Code: 60. DB::Exception: Unk
v2: code 395, message Code: 395. DB::Exception: boom: while exec
v1 LZ4: code 395, message Code: 395. DB::Exception: text in a row","
v1 GZIP: code 395, message {"exception":"Code: 395. DB::Exception: te
v2: code 395, message Code: 395. DB::Exception: text in a row","
v1 LZ4: code 395, message Code: 395, server: 2026cacdf86a, r?+??̶!#븵
v1 GZIP: code 395, message {"exception":"hello","number":0}?{"excepti
v2: code 395, message Code: 395. DB::Exception: boom: while exec
Only lines 3 and 9 are correct. Line 7 (raw compressed bytes) is #3107.
Expected Behaviour
Each line has code 395 and a message that starts with Code: 395. DB::Exception: boom. The server sends that code in the header and as the last text of the body (decompressed, curl -H 'Accept-Encoding: gzip' '…&enable_http_compression=1'; with compress=1 the status and header are the same):
HTTP/1.1 500 Internal Server Error
X-ClickHouse-Exception-Code: 395
Content-Encoding: gzip
{"exception":"Code: 60. DB::Exception: Unknown table x. (UNKNOWN_TABLE) (version 1)","number":0}
...
Code: 395. DB::Exception: boom: while executing 'FUNCTION throwIf(...)'. (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO) (version 26.10.4.207 (official build))
Root cause
- client-v1:
checkResponse(clickhouse-http-client/src/main/java/com/clickhouse/client/http/ApacheHttpConnectionImpl.java:259, the same inHttpUrlConnectionImpl) throws the whole decoded body as the message and does not use theX-ClickHouse-Exception-Codeheader for the code.extractErrorCode(clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseException.java:69) then takes the firstCode: <N>of the message. When the body cannot be decoded,parseErrorFromException(ClickHouseHttpConnection.java:326) starts the message at the firstode:of the raw bytes, with the same result. - client-v2:
readClickHouseError(client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java:517) starts the message at the first<code>.of the body.
The server's exception is the last text of the body. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related:
- #3107 (open) is the LZ4 decoding failure on 26.9+; GZIP shows the same codes without it.
- #3439 (open):
readClickHouseErroralso matches a part of the code at the end of a read. One change of the search can fix both.
Code Example
Reproduction program (Java, 40 lines)
import com.clickhouse.client.*;
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.ServerException;
import com.clickhouse.client.api.query.QuerySettings;
import com.clickhouse.client.config.ClickHouseClientOption;
import com.clickhouse.data.ClickHouseCompression;
import com.clickhouse.data.ClickHouseFormat;
public class ErrorCodeFromRow {
public static void main(String[] args) throws Exception {
String url = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
String password = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
String[] rows = {"Code: 60. DB::Exception: Unknown table x. (UNKNOWN_TABLE) (version 1)",
"Code: 395. DB::Exception: text in a row", "hello"};
ClickHouseNode server = ClickHouseNode.of(url + "/default?user=default&password=" + password);
for (String row : rows) {
// The query fails during execution, after the server produced some rows.
String sql = "SELECT '" + row + "' AS exception, number FROM numbers(10)"
+ " WHERE throwIf(number = 5, 'boom') = 0 SETTINGS max_block_size = 1";
for (ClickHouseCompression alg : new ClickHouseCompression[] {ClickHouseCompression.LZ4, ClickHouseCompression.GZIP}) {
try (ClickHouseClient c = ClickHouseClient.newInstance(ClickHouseProtocol.HTTP);
ClickHouseResponse r = c.read(server).option(ClickHouseClientOption.COMPRESS_ALGORITHM, alg)
.format(ClickHouseFormat.JSONEachRow).query(sql).executeAndWait()) {
} catch (ClickHouseException e) {
System.out.println("v1 " + alg + ": code " + e.getErrorCode() + ", message " + start(e.getMessage()));
}
}
try (Client c = new Client.Builder().addEndpoint(url).setUsername("default").setPassword(password).build()) {
c.query(sql, new QuerySettings().setFormat(ClickHouseFormat.JSONEachRow)).get().close();
} catch (ServerException e) {
System.out.println("v2: code " + e.getCode() + ", message " + start(e.getMessage()));
}
}
}
static String start(String m) {
return m.replaceAll("[\\x00-\\x1f]", "?").substring(0, 42);
}
}
Configuration
Client Configuration
// client-v1: default options, compress_algorithm LZ4 (default) or GZIP
ClickHouseClient.newInstance(ClickHouseProtocol.HTTP).read(server).option(ClickHouseClientOption.COMPRESS_ALGORITHM, alg)
// client-v2: default options
new Client.Builder().addEndpoint(url).setUsername("default").setPassword(password).build()
Environment
- Cloud
- Client version:
mainat 051a7ecfd (0.12.0-rc1-SNAPSHOT); the root-cause files are the same on 8480ca001 - Language version: Java 17 (OpenJDK 17.0.21.1)
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.10.4.207
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none (numbers(10))- Sample data for all these tables: none
Classification: impact: none · area: API & diagnostics (error parsing)
Found by automated analysis (Polyglot AI) while checking clickhouse-js#1175 against the other client repos. Verified against a live server.
- Lingua principale
- Java
- Stelle
- 1.6k
- Fork
- 657
- Merge medio
- 2g 6h
- PR unite (30g)
- 36
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
ClickHouse/clickhouse-java#3464 ·
I maintainer di solito rispondono entro 1 giorno
-
tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ClickHouse/clickhouse-java#3452 ·
I maintainer di solito rispondono entro 1 giorno
-
bug jdbc performance queries sql-parser
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
ClickHouse/clickhouse-java#3451 ·
I maintainer di solito rispondono entro 1 giorno
-
bug jdbc legacy queries
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ClickHouse/clickhouse-java#3444 ·
I maintainer di solito rispondono entro 1 giorno
-
api-diagnostics bug client jdbc
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ClickHouse/clickhouse-java#3439 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ClickHouse/clickhouse-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
quelea-projection/Quelea#749 ·
I maintainer di solito rispondono entro 1 giorno
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
erkamyaman/rust-anything#963 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 76/100
-
Deferred
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Sanne/incus-spawn#2768 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
morluto/rea#15041 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno