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.
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.