[client-v2] Mid-stream server error with response compression: ServerException message starts with result rows, not the server text
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java
- Lĩnh vực
- api, backend-api-design
Hướng nghiên cứu
Bắt đầu với readClickHouseError trong HttpAPIClientHelper.java quanh dòng 519 và theo dõi cách mã ngoại lệ của máy chủ được khớp qua các lần đọc 1024 byte. Tái hiện vấn đề bằng ví dụ Java được cung cấp, sử dụng CSV và các thiết lập nén mặc định. Hoàn tất khi ServerException.getMessage() bắt đầu bằng văn bản lỗi của máy chủ và loại trừ các dòng kết quả đứng trước.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
A query fails after the server has sent result rows, and the response uses the default response compression (compressServerResponse(true)). Then client-v2 throws a ServerException with the correct code, but getMessage() starts with result data, not with the server error text. The message holds all the rest of the response body (0.5 to 1 MB of CSV rows here, 7.5 MB with Native), and the server text is only at its end.
The result depends on the format and on the bytes at the read boundaries. Of the runs below, CSV gave a wrong message in 23 of 23 runs (TabSeparated and Native also failed in each run). The default RowBinaryWithNamesAndTypes failed in 2 of 20 runs with number = 300000, because the server does not always send the same number of rows before the error.
Steps to reproduce
- Create a client with the default configuration.
- Run
SELECT number, throwIf(number = 1000000, 'boom') FROM system.numberswithnew QuerySettings().setFormat(ClickHouseFormat.CSV). - Read
ServerException.getMessage().
Error Log or Exception StackTrace
Output of the program in "Code Example". The second case is a contrast.
CSV, error at 1000000: code=395, message length=1063521
starts: Code: 30,0 531,0 532,0 533,0 534,0 535,0 536,0 537,0 538,0 5
ends: r, 1000000_UInt32), 'boom'_String) UInt8 : 3'. (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO) (version 26.11.2.4 (official build)
RowBinaryWithNamesAndTypes, error at 1000000: code=395, message length=334
starts: Code: 395. DB::Exception: boom: while executing 'FUNCTION th
ends: r, 1000000_UInt32), 'boom'_String) UInt8 : 3'. (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO) (version 26.11.2.4 (official build)
Expected Behaviour
The message starts with the server text and contains no result data, as in the contrast case: Code: 395. DB::Exception: boom: while executing .... The server sends HTTP/1.1 500 with X-ClickHouse-Exception-Code: 395, and this text is the last part of the body, after the rows.
Root cause
readClickHouseError (HttpAPIClientHelper.java:519) compares only the bytes that are left in the current 1024-byte read, so a read that ends with 3, 39, 395 or 395. counts as a match of "395. ". Here the third read ends with 53 of the row 530,0. Lines 526 and 537-543 then add all the rest of the body to the message.
The fix is in readClickHouseError only. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Code Example
Reproduction program (Java, 27 lines)
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.ServerException;
import com.clickhouse.client.api.query.QueryResponse;
import com.clickhouse.client.api.query.QuerySettings;
import com.clickhouse.data.ClickHouseFormat;
public class MidStreamError {
public static void main(String[] args) throws Exception {
try (Client client = new Client.Builder().addEndpoint("http://clickhouse:8123")
.setUsername("default").setPassword(System.getenv("CLICKHOUSE_PASSWORD")).build()) {
for (String[] c : new String[][]{{"CSV", "1000000"}, {"RowBinaryWithNamesAndTypes", "1000000"}}) {
String sql = "SELECT number, throwIf(number = " + c[1] + ", 'boom') FROM system.numbers";
QuerySettings settings = new QuerySettings().setFormat(ClickHouseFormat.valueOf(c[0]));
try (QueryResponse response = client.query(sql, settings).get()) {
System.out.println("no exception");
} catch (Exception e) {
ServerException se = (ServerException) (e instanceof ServerException ? e : e.getCause());
String m = se.getMessage();
System.out.printf("%s, error at %s: code=%d, message length=%d%n starts: %s%n ends: %s%n",
c[0], c[1], se.getCode(), m.length(),
m.substring(0, 60).replaceAll("[^\\x20-\\x7e]", "?"),
m.substring(m.length() - 170, m.length() - 50));
}
}
}
}
}
Configuration
Client Configuration
new Client.Builder().addEndpoint("http://clickhouse:8123")
.setUsername("default").setPassword(password)
.build(); // defaults: compressServerResponse(true)
Environment
- Cloud
- Client version:
main67775d0d3 (0.12.0-rc1-SNAPSHOT) - Language version: Java 17.0.21
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.11.2.4
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none (system.numbers)- Sample data for all these tables: none
Classification: impact: none · area: API & diagnostics (mid-stream errors)
Found by automated analysis (Polyglot AI) while working on ClickHouse/clickhouse-js#1212. Verified against a live server.
- Ngôn ngữ chính
- Java
- Star
- 1.6k
- Fork
- 657
- Merge trung bình
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 36
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc performance queries sql-parser
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc legacy queries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ClickHouse/clickhouse-java#3444 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug client jdbc legacy queries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3438 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ClickHouse/clickhouse-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
quelea-projection/Quelea#749 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
erkamyaman/rust-anything#963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100
-
Deferred
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Sanne/incus-spawn#2768 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
morluto/rea#15041 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày