You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[client-v2] Handle new error tag from ClickHouse #2702
api-diagnosticsArea: public API shape, error reporting, logging, metrics, tracingbugclientModule: the client (client-v2; with legacy: the v1 client)jdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)
Recommendation: Keep open — fix needed
Open PR #3097 handles the tagged frame, but its diff does not apply to main (it changes ClickHouseLZ4InputStream, which main no longer has), and a maintainer paused it. It needs a rebase before review.
Category: Bug
Classification: impact: none · area: API & diagnostics (mid-stream errors)
Status on main: Reproduced on main — after 467003 rows, client-v2 and jdbc-v2 throw Failed to read value for column s; the server error (Code 395) is lost.
Breaking change: No — can be done without a break.
Workaround:wait_end_of_query=1 (QuerySettings.waitEndOfQuery(true), or clickhouse_setting_wait_end_of_query=1 in jdbc-v2) gives the ServerException (contrast case), but the server then sends no row until the query ends.
Analysis: On a failure after HTTP 200, the server sends the header X-ClickHouse-Exception-Tag, ends the body with a tagged __exception__ frame, and cuts the connection (curl exit 18). main does not read that header: HttpAPIClientHelper.java:848 checks only X-ClickHouse-Exception-Code, and :854-856 returns the 200 body as data. The reader then hits the cut stream, and BinaryStreamReader.java:307 reports it as a column read error.
Reproduction: complete program and output
importcom.clickhouse.client.api.Client;
importcom.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
importcom.clickhouse.client.api.query.QueryResponse;
importcom.clickhouse.client.api.query.QuerySettings;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjava.util.Properties;
publicclassRepro {
staticfinalStringURL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
staticfinalStringPASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
// The server sends about 58 MB of rows with HTTP 200, then the query fails at number 500000.staticfinalStringSQL = "SELECT number, repeat(toString(number), 20) AS s, throwIf(number = 500000, 'boom') AS t"
+ " FROM numbers(1000000) SETTINGS max_block_size = 1000";
staticStringdescribe(Throwablee) {
StringBuilders = newStringBuilder(e.getClass().getName() + ": " + e.getMessage());
for (Throwablec = e.getCause(); c != null && c != c.getCause(); c = c.getCause()) {
s.append(" | cause ").append(c.getClass().getName()).append(": ").append(c.getMessage());
}
returns.toString().replace('\n', ' ');
}
publicstaticvoidmain(String[] args) throwsException {
try (Clientclient = newClient.Builder().addEndpoint(URL)
.setUsername("default").setPassword(PASSWORD).build()) {
longrows = 0;
try (QueryResponseresponse = client.query(SQL).get()) {
ClickHouseBinaryFormatReaderreader = client.newBinaryFormatReader(response);
while (reader.next() != null) {
rows++;
}
System.out.println("client-v2 query + reader: no exception, rows=" + rows);
} catch (Exceptione) {
System.out.println("client-v2 query + reader: rows=" + rows + " then " + describe(e));
}
// Contrast: with wait_end_of_query=1 the server sends no row before the error.rows = 0;
try (QueryResponseresponse = client.query(SQL, newQuerySettings().waitEndOfQuery(true)).get()) {
ClickHouseBinaryFormatReaderreader = client.newBinaryFormatReader(response);
while (reader.next() != null) {
rows++;
}
System.out.println("client-v2 query + reader, wait_end_of_query=1: no exception, rows=" + rows);
} catch (Exceptione) {
System.out.println("client-v2 query + reader, wait_end_of_query=1: rows=" + rows + " then " + describe(e));
}
}
Propertiesprops = newProperties();
props.setProperty("user", "default");
props.setProperty("password", PASSWORD);
StringjdbcUrl = "jdbc:clickhouse:" + URL.replaceFirst("^https?:", "") + "/default";
try (Connectionconn = DriverManager.getConnection(jdbcUrl, props);
Statementst = conn.createStatement()) {
longrows = 0;
try (ResultSetrs = st.executeQuery(SQL)) {
while (rs.next()) {
rows++;
}
System.out.println("jdbc-v2 executeQuery: no exception, rows=" + rows);
} catch (Exceptione) {
System.out.println("jdbc-v2 executeQuery: rows=" + rows + " then " + describe(e));
}
}
}
}
Output on main (8480ca001), ClickHouse 26.11.2.4:
client-v2 query + reader: rows=467003 then com.clickhouse.client.api.ClientException: Failed to read value for column s | cause org.apache.hc.core5.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected
client-v2 query + reader, wait_end_of_query=1: rows=0 then com.clickhouse.client.api.ServerException: Code: 395. DB::Exception: boom: while executing 'FUNCTION throwIf(…)' … (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO) (version 26.11.2.4 (official build)) …
jdbc-v2 executeQuery: rows=467003 then java.sql.SQLException: Failed to read value for column s | cause com.clickhouse.client.api.ClientException: Failed to read value for column s | cause org.apache.hc.core5.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected
Automated triage by Polyglot AI. A maintainer makes the final decision.
Checked again on main (1b33bf6dd) with ClickHouse 26.11.7.10, because clickhouse-connect has the same defect (ClickHouse/clickhouse-connect#1290). The defect is still there. Two more entry points than in the reproduction above lose the server error:
Call (the query fails after HTTP 200 and the first rows)
Result
query() + getInputStream(), format TabSeparated
org.apache.hc.core5.http.ConnectionClosedException: Premature end of chunk coded message body: not a ClientException, no code, no server text. With compressServerResponse(false), the bytes that the caller reads include the __exception__ block.
execute()
ExecutionException → ClientException → ConnectionClosedException, no code, no server text
query() + reader, jdbc-v2 executeQuery()
as in the reproduction above
queryAll() (contrast)
ServerException, code 395: it sets waitEndOfQuery(true) (Client.java:2235)
With compressServerResponse(false), a small result is sufficient: SELECT number FROM system.numbers WHERE throwIf(number = 10000, 'failure at row 10000') = 0 LIMIT 20000 SETTINGS max_block_size = 1000 fails after 10049 rows (44 KB). With the default compression, this query gives a ServerException (HTTP 500), so the 1,000,000-row query above is necessary.
A check only in the binary reader does not cover getInputStream() and execute().
Found by automated analysis (Polyglot AI) while checking clickhouse-connect#1290 against the other client repos. Verified against a live server.
api-diagnosticsArea: public API shape, error reporting, logging, metrics, tracingbugclientModule: the client (client-v2; with legacy: the v1 client)jdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)
Activity
[-][client-v2] Handle new error format from ClickHouse[/-][+][client-v2] Handle new error tag from ClickHouse[/+]polyglotAI-bot commentedon Nov 28, 2026
Recommendation: Keep open — fix needed
Open PR #3097 handles the tagged frame, but its diff does not apply to
main(it changesClickHouseLZ4InputStream, whichmainno longer has), and a maintainer paused it. It needs a rebase before review.main: Reproduced on main — after 467003 rows, client-v2 and jdbc-v2 throwFailed to read value for column s; the server error (Code 395) is lost.wait_end_of_query=1(QuerySettings.waitEndOfQuery(true), orclickhouse_setting_wait_end_of_query=1in jdbc-v2) gives theServerException(contrast case), but the server then sends no row until the query ends.Analysis: On a failure after HTTP 200, the server sends the header
X-ClickHouse-Exception-Tag, ends the body with a tagged__exception__frame, and cuts the connection (curl exit 18).maindoes not read that header:HttpAPIClientHelper.java:848checks onlyX-ClickHouse-Exception-Code, and:854-856returns the 200 body as data. The reader then hits the cut stream, andBinaryStreamReader.java:307reports it as a column read error.Reproduction: complete program and output
Output on
main(8480ca001), ClickHouse 26.11.2.4:Automated triage by Polyglot AI. A maintainer makes the final decision.
polyglotAI-bot commentedon Dec 4, 2026
Checked again on
main(1b33bf6dd) with ClickHouse 26.11.7.10, because clickhouse-connect has the same defect (ClickHouse/clickhouse-connect#1290). The defect is still there. Two more entry points than in the reproduction above lose the server error:query()+getInputStream(), formatTabSeparatedorg.apache.hc.core5.http.ConnectionClosedException: Premature end of chunk coded message body: not aClientException, no code, no server text. WithcompressServerResponse(false), the bytes that the caller reads include the__exception__block.execute()ExecutionException→ClientException→ConnectionClosedException, no code, no server textquery()+ reader, jdbc-v2executeQuery()queryAll()(contrast)ServerException, code 395: it setswaitEndOfQuery(true)(Client.java:2235)With
compressServerResponse(false), a small result is sufficient:SELECT number FROM system.numbers WHERE throwIf(number = 10000, 'failure at row 10000') = 0 LIMIT 20000 SETTINGS max_block_size = 1000fails after 10049 rows (44 KB). With the default compression, this query gives aServerException(HTTP 500), so the 1,000,000-row query above is necessary.A check only in the binary reader does not cover
getInputStream()andexecute().Found by automated analysis (Polyglot AI) while checking clickhouse-connect#1290 against the other client repos. Verified against a live server.