Skip to content

Do not ping the server from the client before every query - #111990

Merged
alexey-milovidov merged 27 commits into
masterfrom
client-no-ping-before-query
Aug 12, 2026
Merged

alexey-milovidov merged 27 commits into
masterfrom
client-no-ping-before-query

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

Related: #110068
Related: #111982

Follow-up to #110068, which stopped pinging pooled connections and replaced the Ping-Pong exchange with a non-blocking check of whether the connection is still usable. Connection::checkConnected, which clickhouse-client calls before every query, was the last place still pinging. This extracts that check from forceConnected into Connection::isStale and uses it there too.

The round trip goes away. For 300 trivial queries in one clickhouse-client --multiquery session (counted with strace -c -e trace=sendto,recvfrom):

sendto recvfrom total
before 604 1188 1792
after 304 603 907

And a slow server no longer costs the client its session. A pong that did not arrive within sync_request_timeout was indistinguishable from a closed connection, so under load the client abandoned a perfectly alive session. Re-establishing a connection starts a new session, silently losing the temporary tables, the current database and the session settings of the old one - which surfaces much later in a script as a puzzling error. This is what made the 03101_analyzer_identifiers_* tests flaky on loaded sanitizer runners:

Code: 60. DB::Exception: Unknown table expression identifier 't' in scope SELECT COLUMNS('^c') FROM t. Maybe you meant test_qp0dhise.t?. (UNKNOWN_TABLE)

The server log for that run shows the client dropping a connection it had just used successfully and coming back on a new one 16 seconds later, with no server-side close in between:

19:13:39.131 TCPHandler: Processed in 0.214 sec.          <- last query on the old connection
19:13:55.412 TCPHandlerFactory: TCP Request. Address: [::1]:47616   <- client reconnects
19:13:56.128 TCPHandler: Done processing connection.      <- server only now notices the old socket

This covers both flavours of that flakiness: the tests that combine USE {CLICKHOUSE_DATABASE:Identifier} with unqualified table names (whose remaining client-side bug is fixed separately in #111982) and 03101_analyzer_identifiers_2, which uses CREATE TEMPORARY TABLE and could not be fixed any other way, since temporary tables live in the session.

Trade-off. A connection the server has closed is still re-established: closing it makes the socket readable, which is exactly what the check looks for. But only a close that has already arrived is seen - a connection closed microseconds ago still looks usable, and that failure is reported by the query that runs into it. There is no way around that without a round trip: the answer to a ping is equally out of date the moment it arrives. A server that went away without closing the connection is likewise no longer detected up front. This is the same trade-off #110068 made for pooled connections. The client does not retry such a query, because a query that may have already been executed is not safe to repeat.

Tests. 04651_client_no_ping_before_query is the test for this change and fails if the ping before a query comes back: all the traffic goes through a proxy that delays the beginning of every server response by two seconds, while the client is configured with sync_request_timeout of one second. A client that pings cannot get the Pong in time, so it reconnects and loses the temporary table created by the first query; a client that does not ping is unaffected. Verified both ways - with checkConnected restored to isConnected() && ping(timeouts) the test fails with UNKNOWN_TABLE, which is exactly the session loss described above.

04650_client_reconnect_without_ping covers the re-establishing of a connection that the server closed (idle_connection_timeout = 0), and asserts that the client did reconnect rather than merely that the query succeeded. It is an expect test, so that there is a real pause between the queries: the initial .sql version of it had no such pause and raced with the arrival of the FIN, which is why it failed in the first CI run of this pull request.

The ping is also still used deliberately after a failed query, where it is not a liveness probe but a check that the protocol is still in sync - leftover unread packets make the connection readable, so the new check detects that case as well.

CI report the flakiness was found in: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a58de9c1a55e6577c3a6cafdac5609bc90234ef0&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

clickhouse-client no longer pings the server before every query, which removes a network round trip per query. It also no longer re-establishes the connection - silently starting a new session, and so losing temporary tables, the current database and session settings - just because the server was too slow to answer a ping.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.8.1.1245 (included in 26.8 and later)

Follow-up to #110068, which stopped pinging pooled connections and replaced the
`Ping`-`Pong` exchange with a non-blocking check of whether the connection is
still usable. `Connection::checkConnected`, which `clickhouse-client` calls
before every query, was the last place still pinging; extract the check from
`forceConnected` into `Connection::isStale` and use it there as well.

Two things improve. The ping cost a round trip per query: for 300 trivial
queries in one `clickhouse-client --multiquery` session, the number of network
system calls drops from 1792 to 907 (604 -> 304 `sendto`, 1188 -> 603
`recvfrom`).

And, more importantly, a pong that does not arrive within
`sync_request_timeout` was indistinguishable from a closed connection, so on a
loaded server the client abandoned a perfectly alive session. Re-establishing a
connection starts a new session, which silently loses the temporary tables, the
current database and the session settings of the old one, so this surfaced much
later in a script as a puzzling error, e.g. `UNKNOWN_TABLE` for a table that
certainly exists. It made the `03101_analyzer_identifiers_*` tests flaky on
loaded sanitizer runners, both those using `USE {CLICKHOUSE_DATABASE:Identifier}`
with unqualified table names and `03101_analyzer_identifiers_2`, which uses
`CREATE TEMPORARY TABLE`:

    Code: 60. DB::Exception: Unknown table expression identifier 't' in scope
    SELECT COLUMNS('^c') FROM t. Maybe you meant test_qp0dhise.t?. (UNKNOWN_TABLE)

with the server log showing the client dropping a connection it had just used
and coming back on a new one 16 seconds later.

A connection the server really has closed is still re-established: closing it
makes the socket readable, which is what the check looks for. A server that
went away without closing the connection is no longer detected up front - that
failure now surfaces as an error of the query that runs into it, the same
trade-off #110068 made for pooled connections.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a58de9c1a55e6577c3a6cafdac5609bc90234ef0&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29
@clickhouse-gh

clickhouse-gh Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [448b055]

Summary: ✅


AI Review

Summary

This PR removes the pre-query Ping from clickhouse-client by switching the steady-state liveness check to checkConnectedWithoutRoundTrip, while keeping a round-trip resynchronization only for exchanges that can actually leave the protocol out of sync. On the current head, the earlier gaps around post-error recovery, helper queries, suggestion fallback, drained INSERT failures, and sendQuery preflight failures are all addressed in code and covered by focused regression tests, and I did not find new correctness issues in the diff.

Missing context / blind spots
  • ⚠️ I reviewed the current code, tests, and prior discussion, but I did not execute the new client tests locally. Full PR CI for commit 448b055a5904f77aff0e462c8744b1a0d08d6b07 was still in progress during this review.
Final Verdict

✅ No new findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.60% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.80% +0.00%

Changed lines: Changed C/C++ lines covered: 133/166 (80.12%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jul 26, 2026
`04648_client_reconnect_without_ping` raced with the server: with
`idle_connection_timeout = 0` the server closes the connection as soon as it is
idle, but the `FIN` does not necessarily reach the client before it checks the
socket for the next query, and then the query fails with
`ATTEMPT_TO_READ_AFTER_EOF` instead of being run on a re-established
connection. It failed in every stateless run of this pull request, always with
`--output_format_parallel_formatting 0`, which happens to make the client fast
enough to lose the race:

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111990&sha=4744a66cefffdab16be9499aa7859338197ffdda&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
#111990

Two tests replace it, neither of them timing-dependent.

`04650_client_reconnect_without_ping` keeps the reconnection coverage, but as an
`expect` test, so that there is a real pause between the queries: the server has
certainly closed the connection and the client has certainly seen it. It also
asserts that the client did re-establish the connection, rather than merely
that the query succeeded.

`04651_client_no_ping_before_query` asserts what this change is about, and fails
if the `Ping` before a query comes back. All the traffic goes through a proxy
that delays the beginning of every server response by two seconds, while the
client is configured with `sync_request_timeout` of one second: a client that
pings cannot get the `Pong` in time, so it reconnects and loses the temporary
table created by the first query, while a client that does not ping is
unaffected. Verified both ways - with `checkConnected` restored to
`isConnected() && ping(timeouts)` the test fails with `UNKNOWN_TABLE`, which is
exactly the session loss this change is about.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed: the racy 04648_client_reconnect_without_ping.sql is replaced by two tests (see the updated description), master is merged in, and the review comment is answered.

One thing worth flagging from the same CI run, in case it deserves a decision rather than a shrug: 02184_default_table_engine failed once on arm_binary with

Code: 210. DB::NetException: Connection reset by peer, while reading from socket (peer: [::1]:9000, local: [::1]:41770): while receiving packet from localhost:9000. (NETWORK_ERROR)
(query: SET default_table_engine = 'MergeTree';)

It is not reproducible (the harness re-ran it 111 times with the same settings, all passed), the test also failed once on master on 2026-07-15, and that runner's server log has ~2000 Connection reset by peer entries from other tests, so a transient reset there is nothing new. But it is the shape of failure this change makes visible: a reset that has already arrived still makes the socket readable and is detected, while one that arrives a moment later is now reported by the query instead of causing a silent reconnect. Nothing to fix in the tests for it - just noting it, since it is the trade-off rather than an unrelated flake.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111990&sha=4744a66cefffdab16be9499aa7859338197ffdda&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29

Comment thread src/Client/Connection.cpp Resolved
Dropping the `Ping` before every query also dropped it from the two places where the client
recovers from an error, and those need a round trip.

A query whose exception is thrown before the server reads the block of external data leaves the
protocol desynchronized: the server then reads that block, reports `Unexpected packet Data received
from client` and closes the connection. This happens for every `serverError` hint in a `.sql` test,
which is why `ClientBase` reconnects after an expected error. A non-blocking look at the socket
cannot see a close that has not arrived yet, so under load the client kept the dead connection and
the next query failed with `Connection reset by peer` - `02184_default_table_engine` failed this way
in every stateless job. `02871_clickhouse_client_restart_pager` failed for the same reason on the
client-error path: without the round trip the client did not notice the desynchronization and the
second query continued the first one's stream instead of restarting it.

`checkConnected` goes back to pinging and is used by the recovery paths. The check before every
query - the one this pull request is about - uses the new `checkConnectedWithoutRoundTrip`.

The new test `04655_client_reconnect_after_expected_error` makes the failure deterministic: all the
traffic goes through a proxy that delays everything the server sends, the close included. It was
verified to fail with `ATTEMPT_TO_READ_AFTER_EOF` when the recovery path uses the socket check, and
to pass with the ping.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111990&sha=e20150aba04f61cd502ac6477b2740e388bdfcf9&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
A plain readability probe cannot tell a TLS post-handshake record - a session ticket or a
`KeyUpdate` - from application data, so on a `tcp_secure` connection it reports a healthy idle
session as unusable and the client re-establishes it, losing its temporary tables, current database
and session settings. Use `getSocketState`, which decrypts just enough to tell the two apart.
@alexey-milovidov

alexey-milovidov commented Jul 30, 2026 •

Copy link
Copy Markdown
Member Author

Merged master (the branch was ~1100 commits behind) and pushed; the three touched translation units (Client/ClientBase.cpp, Client/Connection.cpp, Client/LocalConnection.cpp) compile against current master with no changes needed.

The 02184_default_table_engine reds from the first run are gone - they were the error-recovery paths, fixed by keeping the Ping there. The only remaining red is Stress test (arm_tsan): Logical error: SortingAggregatedTransform already got bucket with number 16, which is #111441 (unrelated to the client-side connection check; fixes in progress in #108727 and #112127).

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111990&sha=b8ad16bc10241406a7a8570e6903bddcd40bb63b&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The only red in the last run, AST fuzzer (amd_debug) — logical error Column __text_index_idx_hasToken_... already added for reading (report) — is unrelated to this client-only change: it is a master bug in plan-based parallel replicas over a direct read from a text index, hit by a fuzzed mutation of 04338_text_index_codec_setting_change_merge with the same predicate in both PREWHERE and WHERE. Root-caused and fixed in #112723. Merged master in and pushed to re-run CI.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI status for 961ea501b90: the only red was Stateless tests (arm_binary, parallel) — Server died plus Logical error: 'Bad cast from type DB::ColumnNullable to DB::ColumnString' thrown from MergeTreeDataPartWriterOnDisk::initColumnsSubstreamsIfNeeded on a background mutation task. This is unrelated to this pull request (it touches only the client-side connection check): it is the known master bug tracked in #112459, where MutationHelpers::getColumnsForNewDataPart records the source part's stale column type for a MutateAllPartColumnsTask, so the part writer hands a ColumnNullable to SerializationString. The fix is in #112501 and has not landed on master yet.

Merged the latest master (clean) and pushed; the three touched translation units still compile unchanged.

Comment thread src/Client/ClientBase.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 18/21 (85.71%) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 32e2e03f-5566-4733-a9d0-9a613017b8c0
  • MIRAI run: 9be75b4b-a748-43f6-80ab-8a4da34594c8
  • PR check IDs:
    • clickbench_419602_1786253348
    • clickbench_419608_1786253348
    • clickbench_419619_1786253348
    • tpch_adapted_1_official_419630_1786253348
    • tpch_adapted_1_official_419644_1786253348
    • tpch_adapted_1_official_419672_1786253348

A failed query can leave the protocol desynchronized: the server throws before it reads the
block of external data of that query and then closes the connection. Only the two recovery
paths that reconnect explicitly - the expected-error hint of a test and the client exception
of the interactive loop - used the strong `checkConnected`. An ordinary server exception sets
`have_error` and nothing else, so a session that continues after it (the interactive mode, or
`--ignore-error`) went to the next query through `checkConnectedWithoutRoundTrip`, which cannot
see a close that has not been delivered yet, and failed it with `ATTEMPT_TO_READ_AFTER_EOF`.

Any failed query now marks the connection for resynchronization, and the check before the next
query of the same session costs a round trip - the fast path stays free of it for a session
that has no errors, which is what this pull request is about.

`04666_client_reconnect_after_server_error` covers the case: an error without a test hint under
`--ignore-error`, behind a proxy that delays everything the server sends, the close included.
The proxy is moved to `helpers/delaying_tcp_proxy.py` and shared with `04655`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Addressed the review blocker in de77388c360.

The post-error contract was only preserved on the two paths that reconnect explicitly (an expected-error test hint, and a client_exception in the interactive loop). An ordinary server exception just sets have_error, so a session that continues after it - the REPL, or --ignore-error - went to the next query through checkConnectedWithoutRoundTrip, which cannot see a close that has not been delivered yet.

Now any failed query marks the connection for resynchronization (connection_needs_resynchronization), and the check before the next query of that session is the round-trip checkConnected. A session without errors keeps the fast path, which is the point of this pull request.

New test 04666_client_reconnect_after_server_error: an error without a test hint under --ignore-error, behind a proxy that delays everything the server sends including the close. A/B verified locally against a real server - without the fix the following query reports ATTEMPT_TO_READ_AFTER_EOF, with it the output is clean. The proxy is now shared in tests/queries/0_stateless/helpers/delaying_tcp_proxy.py (also used by 04655).

The only red before this push was CH Inc sync. Its two private failures are unrelated: 01076_parallel_alter_replicated_zookeeper (the private harn'ess own rerun says "All reruns passed. The failure is not reproducible") and a Distributed cache processed no requests on remote storage stress check. Both will be re-run for the new head.

Comment thread src/Client/ClientBase.cpp Resolved
…y exchange starts

A query can fail on the client before anything has been sent to the server -
for example, on the local checks of `INTO OUTFILE`. The catch of the
multi-query loop used to arm `connection_needs_resynchronization` for every
client-side exception, so a session that continued after such a purely local
failure (`--ignore-error`, the interactive mode) resynchronized the connection
with a round trip; if the `Pong` did not arrive within `sync_request_timeout`,
the client silently reconnected and lost the session state (temporary tables,
the current database, session settings) even though the protocol never left
sync.

Now the flag is armed right before the query is sent (in `processOrdinaryQuery`
and `processInsertQuery`) and cleared when the exchange completes cleanly, so
only an error of a query whose exchange has actually started leads to the round
trip. The `help` and AI-generator exchanges (`fetchDocumentation`,
`executeQueryForSingleString`) follow the same discipline, so a failure there
no longer leaves the connection silently desynchronized for the next query.

The new test `04692_client_no_reconnect_after_local_error` is A/B verified:
with the flag armed in the catch, the client reconnects after the local error
and the subsequent query fails with `UNKNOWN_TABLE`.
… fallback fails with a server exception

`Suggest::fetch` sends its query with the terminating empty block
(`with_pending_data` is false), so a `Protocol::Server::Exception` is
the terminal packet of a protocol-consistent exchange, just like in the
`help` / AI helper exchanges. Keeping `connection_needs_resynchronization`
armed after such a failure made the next query of the session pay the
round-trip `checkConnected`, whose ping can time out on a slow but alive
server and silently reconnect away the temporary tables, the current
database and the session settings.

`Suggest` now tracks whether the last exchange ended with the protocol
in sync - with `EndOfStream` or with a server exception - and the
fallback site clears the flag based on that instead of `getLastError`,
which cannot distinguish a server exception from a transport failure.

The new test `04814_client_no_reconnect_after_suggest_error` is
deterministic: `max_sessions_for_user = 1` makes the background
suggestions loader fail with `USER_SESSION_LIMIT_EXCEEDED` (waited for
with `--wait_for_suggestions_to_load`), so the first interactive input
triggers the fallback on the main connection - after the temporary
table was created by the initial queries of the same session - and the
fallback fails on the server with `max_result_rows = 1`. A/B verified:
with the old condition restored, the client reconnects and the test
fails with 'the client reconnected after the suggestions failure'.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI status of f96a5963e95 (all unrelated to this client-side change; a fresh run is triggered by the new commit):

The new commit ab3193f33a6 addresses the review finding about the suggestions fallback (see the thread) and merges current master.

@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 448b055a5 with master fd2595cd4 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of d134c6da3; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.64 MiB 687.63 MiB -3.01 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

287 translation units recompiled, 1474 s compile time in total, 123 of them have a recent master baseline.

Translation units without a recent master baseline:

  • contrib/rocksdb-cmake/__/rocksdb/table/block_based/block_based_table_reader.cc: 6.4 s
  • contrib/google-cloud-cpp-cmake/__/google-cloud-cpp/google/cloud/storage/internal/rest/stub.cc: 6.2 s
  • contrib/rocksdb-cmake/__/rocksdb/db/write_batch.cc: 5.9 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/system/stacktrace.cpp: 5.2 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc…: 5.0 s

Job report

alexey-milovidov and others added 2 commits August 7, 2026 18:19
…flight of `sendQuery`

`connection_needs_resynchronization` was armed right before `connection->sendQuery`,
but `Connection::sendQuery` can throw during its purely local preflight - for example,
on the validation of `network_compression_method` - before the first byte of the query
packet has been written. The flag stayed armed for a failure that never touched the
wire, so the next query of an `--ignore-error` or interactive session resynchronized
the connection with a round trip, and behind a slow server the ping could time out and
silently reconnect away the session state.

The arming is now encapsulated in `ClientBase::armResynchronizationAndSendQuery`,
which disarms the flag again when the failed `sendQuery` has left the connection
alive: a failure after `Connection::sendQuery` has started writing always disconnects
the connection (see the `SCOPE_EXIT` there), so a connection that is still alive means
that nothing has been sent. Applied to all four exchanges on the shared connection:
ordinary queries, `INSERT`, and the two help exchanges.

Adds `04818_client_no_reconnect_after_send_preflight_error`: a per-query
`SETTINGS network_compression_method = 'T64'` fails exactly one query in the
preflight, behind the delaying proxy with `sync_request_timeout = 1`.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Addressed the AI review blocker in a0af351: connection_needs_resynchronization is no longer left armed when Connection::sendQuery fails in its local preflight (e.g. the validation of network_compression_method) before the first byte of the query packet has been written. The arming is encapsulated in ClientBase::armResynchronizationAndSendQuery, which disarms the flag when the failed call left the connection alive — a failure after sendQuery has started writing always disconnects (its SCOPE_EXIT), so an alive connection means nothing was sent. New A/B-verified test: 04818_client_no_reconnect_after_send_preflight_error. Master merged.

The single CI red on ab3193f, Stress test (amd_tsan) — Logical error: '... typeid(*this) == typeid(rhs)' in IColumn::assertTypeEquality — is unrelated to this client-only change: the stack is HashJoin buildAdditionalFilter inserting a mismatched column type in a mixed JOIN ON condition, which is fixed by the open PR #113534 (not yet on master, so the red cannot be cleared by merging).

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI on a0af351a3 had two reds, both unrelated to this change:

@groeneai, investigate the read-path Bad cast failure above (STID 4256-3fc1) and provide a fix in a separate PR. If a fix is already in progress, link it here.

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

@alexey-milovidov Your read of the second red is right on both counts, and the fix is already open: #113925, published at 06:19Z, about 20 minutes after your comment, which is why it was not linkable yet.

Confirming the distinction you drew, which I had measured the same way independently. #113891 is the write path (SerializationString::serializeBinaryBulk -> initColumnsSubstreamsIfNeeded -> MutateTask::execute); this one is the read path (SerializationNullable::enumerateStreams -> collectOffsetsColumns in inplaceBlockConversions.cpp -> IMergeTreeReader::fillMissingColumns -> MergeTreeReadersChain::executeActionsBeforePrewhere). Different site, different fix. I checked your presence point rather than taking it: at a0af351a31e, #112501's merge commit is an ancestor (behind_by: 0) while #113925's head is not, so this is genuinely not a cached pre-fix artifact.

It is my own regression, from my merged #113225, so master only. No released version is affected and no backport is owed. getSubcolumnsOfNested built a synthesized Nested group's element type from whichever entry it saw first, and a subcolumn entry's type in storage is necessarily the metadata type, so it outvoted the part's own older type and the type-directed enumerateStreams walk then asserted on the first wrapper the part does not carry. #113925 makes a plain entry replace a subcolumn entry's contribution and never the reverse. Five lines reach it on pristine master with all table settings default; the reproducer, the projection-order trigger, and the Array(Tuple(...)) and Array(Dynamic) variants that are fixed too are at #113595, comment 5223949125, so I am not repeating them here.

One thing worth knowing given you tracked this by STID. This one signature carries two, 3520-4525 and 4256-3fc1, for a single defect, because the hash covers demangled template arguments and inlining and the two arms are different sanitizer builds. A watch keyed on either STID alone misses the other, including the master hit you cite. Keying on collectOffsetsColumns, or on the ColumnString to DB::ColumnNullable message, catches both.

On your first red I agree it is unrelated and have nothing to add.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Triage of the three reds on 279101c7131 — all unrelated to this client-only change, each with a fix in flight:

Review state is clean (no unresolved threads, AI verdict has no findings); nothing to push on this branch. Awaiting the fixes above to land, a CI re-run, and a human merge.

alexey-milovidov and others added 2 commits August 9, 2026 03:00
…04757 and 04814

The expect-based tests 04757_client_help_error_keeps_session and
04814_client_no_reconnect_after_suggest_error ended with a teardown
(`DROP USER`) whose exit status replaced the exit status of `expect`,
so a failing expect script could not fail the test through the exit
code (only through the output diff). Capture the status of `expect`
and exit with it after the teardown.

Both tests verified to still pass against a local server built from
this branch.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The CH Inc sync red (tests failed (1 new, 2 known)) on 279101c7131 is triaged, and the private-side AI review of the sync PR is addressed; test hardening + a master merge are pushed as 444dad6c9e3a + 448b055a5904.

The three failing private jobs are all unrelated to this client-only change:

  • Integration tests (amd_asan_ubsan, db disk, 4/7): no test failed — all 1089 passed, but the session went 19 seconds over its 7200-second budget (session-timeout), pushed over the edge by a slow test_keeper_mntr_pressure run. Pure infra/timing.
  • Integration tests (amd_tsan, 3/6): test_lightweight_updates_gc/test.py::test_lwu_gc_cross_replica failed with a server-side Keeper lock timeout (Failed to get lock with 100 tries for lightweight update, TIMEOUT_EXCEEDED) and passed on the retry — flaky under TSan slowness.
  • Stress test (arm_asan_ubsan, SharedCatalog): the known LSan leak of ASTWithElement/Context copies via QueryTreeBuilder::buildSelectExpression / Planner — the materialized-CTE reference cycle, fix open in Fix a table permanently stuck in the drop queue after a failed materialized-CTE query #113397. Same family as the public Stress test (amd_asan_ubsan) red already triaged above.

The private sync PR's AI review posted a Block verdict; two findings fixed, one refuted:

  • Fixed (444dad6c9e3a): in 04757_client_help_error_keeps_session and 04814_client_no_reconnect_after_suggest_error the trailing DROP USER teardown replaced the exit status of expect, so a failing expect script could only fail the test through the output diff. The status is now captured and propagated. Both tests re-verified against a local server built from this branch.
  • Refuted: the finding that the forceConnected contract now lets a pooled connection that died without a delivered FIN escape ConnectionPool::get into callers that lack ConnectionEstablisher's retry. That contract is not introduced by this PR — the no-round-trip forceConnected landed on master in Do not ping pooled connections before use; reconnect on failure instead #110068. This PR's diff there only extracts the probe into Connection::isStale (for reuse by the pre-query check) and makes it TLS-aware via getSocketState, which strictly reduces false "stale" verdicts on secure connections. A connection that died without a FIN behaves identically before and after this PR: nothing is readable on the socket in either version, so both hand it out, and the failure surfaces at first use — as the code comment documents, a Ping would be equally out of date the moment its answer arrives. Revisiting that design belongs to Do not ping pooled connections before use; reconnect on failure instead #110068, not here.

The three public reds on 279101c7131 remain the previously-triaged unrelated ones (SZ3 LSan → #113916, 04630 stress S3 keys → #113978, AST fuzzer RemoteSource → #113469). Master is merged in; the new push triggers a fresh CI and a fresh sync run.

pull Bot pushed a commit to CrazyForks/ClickHouse that referenced this pull request Aug 9, 2026
…s runs

The test copies a packed part directory with plain cp to simulate a stale
tmp_merge directory. Stress jobs flip the default MergeTree storage_policy
to (cached) S3 or Azure in the server config without passing the
corresponding flag to clickhouse-test, so the no-object-storage tag does
not protect them. On a remote disk, cp duplicates the metadata files
without incrementing the blob reference counts, and reclaiming the stale
directory deletes blobs still referenced by the live part - every later
read of it fails with 'The specified key does not exist', tripping the
stress check's no-such-key detector. Pin storage_policy = 'default' so the
part directory is always a genuine local copy.

Seen on every stress run since the test merged, e.g.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111990&sha=279101c71314bcf8e46a083cbf950ecb2143aa44&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29
(PR: ClickHouse#111990)

Co-Authored-By: Claude Fable 5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad.

@alexey-milovidov alexey-milovidov self-assigned this Aug 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 12, 2026
Merged via the queue into master with commit 9af86bf Aug 12, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the client-no-ping-before-query branch August 12, 2026 14:44
alexey-milovidov pushed a commit that referenced this pull request Aug 12, 2026
Conflicts in `src/Client/ClientBase.cpp`, all with the connection
resynchronization of #111990, which landed in master while this branch
removed or renamed the two functions it touched:

- `executeQueryForSingleString` no longer exists here (the client-side AI
  transport calls `executeInternalQueryForAI`/`executeScalarQueryForAI`
  instead), so its side of the conflict is dropped.
- `fetchDocumentation` became `fetchInternalQueryResult`, which now follows
  the same discipline: resynchronize before the exchange, arm the flag while
  sending, and clear it on `EndOfStream` or on a server exception. The
  comments that referred to `executeQueryForSingleString` are inlined here
  and referenced from `runInteractive`.
- `runQueryForAI` copied the old "reconnect after a client-side exception"
  pattern from the interactive loop, which #111990 replaced: it now
  resynchronizes only when the flag is armed, so a local failure no longer
  pays for a round trip that could silently reconnect away the session state.
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants