Repository navigation
Description
Description
With the default settings (compress=1), client-v2 loses the server error text when the server returns HTTP 403 for a query-level error, for example ACCESS_DENIED (497). The error code is correct (from X-ClickHouse-Exception-Code), but the message is not:
- ClickHouse 26.9+ (default codec ZSTD):
Code: 497. DB::Exception: <Unreadable error message> (transport error: 403) - ClickHouse 26.8 and older (LZ4): raw LZ4 bytes replace parts of the message.
jdbc-v2 with its default URL is affected too. The message is correct with compressServerResponse(false) (jdbc compress=0) or useHttpCompression(true), for HTTP 400/500 errors, and for authentication failures (516, also HTTP 403).
Steps to reproduce
- As
default:CREATE USER lead_noacc IDENTIFIED WITH plaintext_password BY 'pw'(no grants),CREATE TABLE default.lead_t (x Int32) ENGINE = MergeTree ORDER BY x. - As
lead_noacc, with the default client settings, runDESCRIBE TABLE default.lead_torSELECT * FROM default.lead_t(code example below). - Look at the exception message.
Error Log or Exception StackTrace
Output of the code example on ClickHouse 26.9.4.3:
[v2 default ] DESCRIBE TABLE default.lead_t -> ServerException: Code: 497. DB::Exception: <Unreadable error message> (transport error: 403) (queryId= f54e9de5-...)
[v2 compress=false ] DESCRIBE TABLE default.lead_t -> ServerException: Code: 497. DB::Exception: lead_noacc: Not enough privileges. To execute this query, it's necessary to have the grant SHOW COLUMNS ON default.lead_t. (ACCESS_DENIED) (version 26.9.4.3 (official build))
[v2 httpCompression] DESCRIBE TABLE default.lead_t -> ServerException: Code: 497. DB::Exception: lead_noacc: Not enough privileges. ... (ACCESS_DENIED) ...
[v2 default ] SELECT * FROM default.lead_t -> ServerException: Code: 497. DB::Exception: <Unreadable error message> (transport error: 403) (queryId= f2e94e32-...)
[v2 default ] SELECT throwIf(1, 'boom-400') -> ServerException: Code: 395. DB::Exception: boom-400: while executing ... (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO) ...
[v2 default wrong-pw] SELECT 1 -> ServerException: Code: 516. DB::Exception: lead_noacc: Authentication failed: password is incorrect, or there is no user with such name. (AUTHENTICATION_FAILED)
[jdbc default ] INSERT -> SQLException: Code: 497. DB::Exception: <Unreadable error message> (transport error: 403) (queryId= 393ab454-...)
[jdbc compress=0] INSERT -> SQLException: Code: 497. DB::Exception: lead_noacc: Not enough privileges. To execute this query, it's necessary to have the grant INSERT ON default.lead_t. (ACCESS_DENIED) ...
On 26.8.1.2041 (LZ4), default settings (cat -v output):
[v2 default ] DESCRIBE TABLE default.lead_t -> ServerException: Code: 497. DB::Exception: lead_noacc: Not enough privileges. To execute this query, it's necessary to have the grant SHOW COLUMNS ON default.s^@M-oM-?M-=+t. (ACCESS_DENIED) ...
[jdbc default ] INSERT -> SQLException: Code: 497. DB::Exception: lead_noacc: Not enough privileges. To execute this query, it's necessary to have the grant INSERT ON default.m^@M-oM-?M-=+t. (ACCESS_DENIED) ...
Expected Behaviour
The message contains the server text, as with compress=0. The server sends it in a compressed block (on 26.9, byte 16 is 0x90, ZSTD), but it sends an authentication failure, also HTTP 403, as plain text. So the HTTP status does not tell if the body is compressed:
$ curl -s -D - -u lead_noacc:pw 'http://clickhouse:8123/?compress=1&query=DESCRIBE+TABLE+default.lead_t' -o body
HTTP/1.1 403 Forbidden
X-ClickHouse-Exception-Code: 497
$ od -A d -t x1 -N 24 body
0000000 e8 28 96 52 39 a5 8a 6b 98 c2 07 ec b1 2c a5 a3
0000016 90 bd 00 00 00 c9 00 00 00 28 b5 2f
$ curl -s -D - -u lead_noacc:bad 'http://clickhouse:8123/?compress=1&query=SELECT+1' -o body
HTTP/1.1 403 Forbidden
X-ClickHouse-Exception-Code: 516
$ od -A d -c -N 16 body
0000000 C o d e : 5 1 6 . D B : : E
Root cause. HttpAPIClientHelper.wrapResponseEntity (client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java:1121) does not decompress a 401 or 403 response:
if (serverCompression && !(httpStatus == HttpStatus.SC_FORBIDDEN || httpStatus == HttpStatus.SC_UNAUTHORIZED)) {readClickHouseError (:488) then scans the compressed bytes for 497. DB::Exception:. With ZSTD it does not find the prefix and writes <Unreadable error message> (:543-544); with LZ4 it finds the prefix and copies the LZ4 match tokens into the message.
The fix is one condition in wrapResponseEntity. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: #3322 changes the partial-header handling in readNotClickHouseError, not this condition.
Code Example
Reproduction program (Java, 22 lines)
// as default: CREATE USER lead_noacc IDENTIFIED WITH plaintext_password BY 'pw'
// CREATE TABLE default.lead_t (x Int32) ENGINE = MergeTree ORDER BY x
try (Client c = new Client.Builder().addEndpoint("http://localhost:8123")
.setUsername("lead_noacc").setPassword("pw")
.build()) { // compressServerResponse(true) is the default
c.query("DESCRIBE TABLE default.lead_t").get().close();
} catch (Exception e) {
System.out.println(e.getMessage());
// actual (26.9+): Code: 497. DB::Exception: <Unreadable error message> (transport error: 403) ...
// expected: Code: 497. DB::Exception: lead_noacc: Not enough privileges. ... (ACCESS_DENIED) ...
}
// jdbc-v2, default URL
Properties p = new Properties();
p.setProperty("user", "lead_noacc");
p.setProperty("password", "pw");
try (Connection conn = new com.clickhouse.jdbc.Driver().connect("jdbc:clickhouse://localhost:8123/default", p);
Statement st = conn.createStatement()) {
st.execute("INSERT INTO default.lead_t VALUES (1)");
} catch (SQLException e) {
System.out.println(e.getMessage()); // same <Unreadable error message> (transport error: 403)
}Configuration
Client Configuration
// defaults: compressServerResponse(true), useHttpCompression(false)
// jdbc-v2: default URL (compress not set)Environment
- Cloud
- Client version: client-v2 / jdbc-v2
0.12.0-rc1-SNAPSHOT(mainf9586aba0) - Language version: Java 17
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.9.4.3 and 26.10.3.7 (unreadable), 26.8.1.2041 (message corrupted)
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: in Steps to reproduce- Sample data for all these tables: not needed (the user has no grants)
Classification: impact: none · area: API & diagnostics (HTTP 403 error messages)
Found by automated analysis (Polyglot AI) while working on #3326. Verified against a live server. Shortened on 2026-11-20: the edit history has the first version.
Activity