Skip to content

Bound the AST fuzzer liveness probes and teardown diagnostics - #115915

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/bound-ast-fuzzer-liveness-probes
Aug 22, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/bound-ast-fuzzer-liveness-probes

Conversation

@groeneai

@groeneai groeneai commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

---8<--- PR BODY BELOW (first line above is the intended title) ---8<---

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Not user-facing: bounds the AST fuzzer job's own liveness probes and teardown diagnostics.

Description

In AST fuzzer (amd_debug, targeted) on #111394 the post-fuzz liveness probe loop
(report)
took 66 minutes to reach a verdict it budgets 5 seconds per attempt for: 5m27s per probe, twelve
times.

Root cause: --receive_timeout is inert until the handshake completes. Connection.cpp:319-320
puts both socket timeouts on handshake_timeout before sendHello and
only swaps them at :407-408, and the client CLI's handshake fallback is 300000 ms
(ConnectionParameters.cpp:177) even though the setting's own default is 10000. So a server that
accepts TCP but never finishes the handshake never reaches the 5 second bound. Against a listener
that accepts and never replies, --receive_timeout=5 alone blocks 300 s (322 s over TLS, the
fuzzer's port, where the message reads "writing to socket" and misattributes to send_timeout);
--handshake_timeout_ms=30000 bounds it at 30 s, and 5000 and 12000 confirm the bound tracks the
value passed.

Four probes therefore get one extra token, and the two best-effort diagnostics get a hard command
deadline, --kill-after included because a bare timeout waits indefinitely for a child ignoring
SIGTERM (12 s for a 3 s budget). No loop bound, branch or verdict changes: I ran the loop's five
outcomes against the patched and unpatched text and got identical results.

30000 rather than 10000 because the merged 7ec04d1132644a7 documents a healthy server needing
over 10 s to send Hello on a loaded lane, and each retry restarts the handshake. My worst healthy
handshake under 65 concurrent queries was 0.148 s.

This does not fix whatever wedged the server, and would not have turned that run green: it
genuinely failed 12 consecutive probes. It removes about 54 minutes of wasted runner time per
occurrence, and brings three over-cap scenarios to 188 min inside the 5 hour cap.

Related: #111892 (same file, memory-stuck angle), #112927 (same remedy, stress harness).


Workflow [PR]
Sync PR [sync-upstream/pr/115915]

The post-fuzz liveness probe loop in run-fuzzer.sh is written to spend 5 seconds
per probe, but each probe can block for 300 seconds. On PR ClickHouse#111394's
AST fuzzer (amd_debug, targeted) job the loop took 66 minutes to reach its
verdict: 5m27s per probe, twelve times.

--receive_timeout does not apply until the handshake completes. Connection.cpp
sets both socket timeouts to handshake_timeout before sendHello and only swaps
them to receive_timeout/send_timeout afterwards, and the client CLI's handshake
fallback is DBMS_DEFAULT_RECEIVE_TIMEOUT_SEC * 1000 = 300000 ms, even though the
setting's own declared default is 10000. A server that accepts the TCP
connection but never finishes the handshake therefore holds each probe for
300 seconds. The fuzzer's port is TLS and the TLS handshake is deferred to the
first send, so the error text reads "writing to socket", which invites a wrong
attribution to send_timeout; elapsed time discriminates the two.

Measured against a listener that accepts and never replies: --receive_timeout=5
alone blocks 300s (322s over TLS); adding --handshake_timeout_ms=30000 bounds it
at 30s, and 5000 and 12000 confirm the bound tracks the value passed.

30000 rather than 10000 because 7ec04d1 documents a healthy server
needing more than 10s to send Hello on a loaded lane, and a retry does not help
since each attempt spawns a fresh client and restarts the handshake from zero.
The worst healthy handshake measured on a debug server under 65 concurrent
queries was 0.148s, so the margin is large.

The two best-effort diagnostics get a hard command deadline instead of a flag: a
diagnostic can stall pre-Hello, post-Hello or inside the query itself, and one
wall-clock cap covers all three. --kill-after is required because a bare timeout
only sends SIGTERM and then keeps waiting: measured 12s for a 3s budget against
a child that ignores it. Both call sites were already ||:-guarded, so the signal
cannot abort the script before the status.tsv write.

No loop bound, branch or verdict is changed. Running the loop's five outcomes
(immediate success, connection refused, persistent timeout,
TOO_MANY_SIMULTANEOUS_QUERIES, MEMORY_LIMIT_EXCEEDED) against the patched and
unpatched text gives identical results, including the final timeouts counter;
two mutations of the loop do shift those results, so the comparison is not
vacuous. In particular timeouts_max stays at 12, since lowering it would weaken
the anti-false-positive property added in ClickHouse#108582.

This does not fix whatever wedged the server and would not have turned the cited
run green: that server genuinely failed 12 consecutive probes, so the job fails
either way. What it removes is about 54 minutes of wasted runner time per
occurrence, and three reachable scenarios whose worst case exceeds the 5 hour job
cap today (bootstrap readiness, post-gdb readiness, and all-busy probing) now
peak at 188 minutes.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Aug 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Two review rounds before this was published; the second model reported no findings on the
diff in either. Everything found was in the PR text, not the code.

Fixed:

  • ❌ The headline saving was stated as 63 minutes. It matches no cost model: from the measured
    327 s per probe it is 12 x 327 = 65.4 min before and 12 x 57 = 11.4 after, i.e. 54.
    63 corresponded to a ~5 s probe cost, which is the misconception this change corrects.
  • ❌ Two Connection.cpp citations were off. The timeout swap is at :407-408, not
    :411-412 (those are inside catch (NetException &)), and the pre-handshake set is
    :319-320, not :319-321 (:321 is setNoDelay).
  • ❌ The validation notes claimed 12 clickhouse-client invocations with 6 excluded. The file
    has 9 executions: 6 bounded here, 3 left alone with a reason each.
  • 💡 A comment referenced a test file that no longer exists on master; dropped.

Checked and left alone:

One point worth stating because it is stronger than the margin argument in the description:
the client bound now equals the server's own handshake ceiling (handshake_timeout_milliseconds,
30000). The server's deadline throws Handshake timeout exceeded, which does not contain
the Timeout exceeded while text the retry branch matches, so a handshake over 30 s already
ended the loop immediately before this change and can now only reach the retryable branch.
The change cannot turn a passing probe into a failing one.

Session id: cron:clickhouse-review-slot-11:20260822-132300

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? YES. python3 blackhole.py 19677 & (a listener that accepts and never replies), then clickhouse-client --host 127.0.0.1 --port 19677 --receive_timeout=5 -q "SELECT 1" blocks 300 s every time, 322 s with --secure. Not statistical.
b Root cause explained? Connection.cpp:319-320 sets both socket timeouts to handshake_timeout before sendHello and only swaps them to receive_timeout at :407-408. The client CLI's handshake fallback is 300000 ms (ConnectionParameters.cpp:177) even though the setting's own default is 10000, so a pre-Hello wedge makes --receive_timeout=5 unreachable and each probe costs 300 + 5 + 1 s. Twelve of those is the reported 66 min.
c Fix matches root cause? YES. It bounds the exact phase that is unbounded, in-client, at the line that states the 5 s intent. timeouts_max is untouched (lowering it would weaken the anti-false-positive property #108582 added), no loop bound is reduced, no assertion widened.
d Test intent preserved / new tests added? Preserved: the loop's five outcomes are byte-identical to the unpatched text (see (e)). No committed test, deliberately: the harness that used to cover this loop was removed from ci/tests/ and that directory is under an active removal program, so a new arm there would be deleted; it also mocked sleep away, which would make a timing assertion vacuous. Validation is a throwaway suite, per .claude/CLAUDE.md.
e Both directions demonstrated? YES on every claim. Probe: 300.4 s plain / 322.6 s TLS unbounded, vs 30.2 s bounded, with 5000 ms -> 5.2 s and 12000 ms -> 12.2 s controls. Diagnostic: 120.0 s unwrapped (cut off by my own cap, listener asserted live first) vs 20.0 s wrapped. Verdicts: identical patched vs unpatched, and two mutations (timeouts_max=12->3, TMSQ branch not resetting the counter) both shift the result, so the comparison is not vacuous.
f Fix is general across code paths? YES. All four probe sites are patched, not only the one that fired, plus both best-effort diagnostics, found by enumerating every clickhouse-client invocation in the file (9 in total; the 3 left alone are excluded with a stated reason each: the deliberate 300 s gdb-attach wait, the already-bounded fuzzer, and the one-shot IS_ASAN query). The same defect in the stress harness is already covered by #112927 and is not duplicated here.
g Fix generalizes across inputs? YES for the axes that exist here (no C++ types involved): plain TCP and TLS (the fuzzer's port is TLS, and that is where the error text misleads), both the argv[0]-symlink and subcommand invocation forms with a bogus-flag Code: 552 control, six server states (healthy, pre-Hello wedged, stalled inside the query, refused, TOO_MANY_SIMULTANEOUS_QUERIES, MEMORY_LIMIT_EXCEEDED), and three handshake values confirming the bound tracks the value passed.
h Backward compatible? YES, trivially. CI harness only: no C++, no setting default changed, no SettingsChangesHistory.cpp entry, no user-facing surface. The 300 s client fallback in ConnectionParameters.cpp is deliberately left alone, since changing a client default would be user-visible. Blast radius is the jobs that run this script.
i Invariants and contracts preserved? Invariant: no liveness or diagnostic clickhouse-client invocation in this script may block longer than an explicit stated budget; probes bound both connection phases in-client so their error text survives for the loop to classify, while diagnostics use a wall-clock deadline that also covers query execution. Holds on all paths: probes still emit Code: 209 ... Timeout exceeded while, so all four branches classify as before; the diagnostics stay ||:-guarded and returned 0 in all three stall modes, so set -e cannot abort before the status.tsv write and the timeouts counter is provably unperturbed.

Session id: cron:clickhouse-impl-slot-7:20260822-073900

@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6381c18]

Summary: ✅


AI Review

Summary

This PR reduces several long waits in ci/jobs/scripts/fuzzer/run-fuzzer.sh by adding --handshake_timeout_ms=30000 to the liveness probes and wrapping two best-effort diagnostics in timeout. The diagnostic wrappers are fine, but the main probe change still does not guarantee a wall-clock bound on the client, so one important part of the PR's contract remains unmet.

Findings

⚠️ Majors

  • [ci/jobs/scripts/fuzzer/run-fuzzer.sh:152,207,340,372] The new probe bound relies on --handshake_timeout_ms, but on the client that setting is only copied into the socket send/receive timeouts in src/Client/Connection.cpp; the client never arms ReadBufferFromPocoSocketBase::setHandshakeTimeout, so there is no end-to-end handshake stopwatch. A peer that trickles TLS or Hello bytes just under the 30 s threshold can therefore keep every probe alive indefinitely, which defeats the stated goal of bounding stalled liveness checks. Suggested fix: wrap each probe in a wall-clock timeout ... clickhouse-client ..., or add a real client-side handshake deadline and use that instead.
Final Verdict

Request changes: the probe path still lacks a hard wall-clock deadline, so the runner-time bound this PR promises is not yet guaranteed.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim, could you review this? The post-fuzz liveness probe loop in run-fuzzer.sh budgets 5 s per probe, but --receive_timeout does not apply until the handshake completes, so against a server that accepts TCP and never sends Hello each probe ran the 300 s client handshake fallback instead, 66 min for the twelve probes. This passes --handshake_timeout_ms=30000 on the four probes and puts a wall-clock deadline on the two best-effort diagnostics, leaving timeouts_max and every branch unchanged.

# --receive_timeout governs the socket only once the handshake has completed; until
# then both directions run on handshake_timeout_ms, whose client-side default is 300s.
# A probe needs both bounds to be held to the budget it asks for.
if clickhouse-client --handshake_timeout_ms=30000 --receive_timeout=5 --query "SELECT 1" 2> err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

--handshake_timeout_ms=30000 is not a hard wall-clock bound on the client, so these probes are still unbounded in the failure mode this PR is trying to cap. Connection::connect only copies handshake_timeout into the socket send/receive timeouts (src/Client/Connection.cpp), and the client never calls ReadBufferFromPocoSocketBase::setHandshakeTimeout (src/IO/ReadBufferFromPocoSocket.cpp:163-173; the only caller is the server-side TCPHandler). A peer that drip-feeds TLS / Hello bytes just under 30 s therefore resets the wait on every read and can keep the loop alive far longer than 30 s. Please wrap the probe itself in timeout ... clickhouse-client ... (or add a real client-side handshake deadline) instead of relying on handshake_timeout_ms alone.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The reading of the code is right: setHandshakeTimeout has exactly one caller,
src/Server/TCPHandler.cpp:390, so on the client handshake_timeout_ms is a per-read socket
timeout and not a wall-clock stopwatch.

That property is the same before and after this change, though. Measured against three peers
(debug build, outer timeout 100, so rc=124 means still running at 100s):

peer --receive_timeout=5 only with --handshake_timeout_ms=30000
accepts, never replies 100.0s, rc=124 30.34s, rc=209
sends 3 bytes of Hello, then silent 100.0s, rc=124 30.31s, rc=209
drip-feeds 1 byte/s forever 100.0s, rc=124 100.0s, rc=124

Row 3 is the peer you describe, and it is unbounded in both columns, so it is not something this
change introduces or worsens. Rows 1 and 2 are what it fixes, and row 2 is the failure mode in the
linked report: a server that got partway through the handshake and wedged. The oracle does detect
bounds, 8000 gives 8.24s and 30000 gives 30.34s with the value named in the error, so row 3 is
an observation about the peer rather than a blind harness.

I am not taking the timeout wrapper, because I measured it inverting the verdict:

timeout --signal TERM --kill-after=10 40 clickhouse-client --handshake_timeout_ms=30000 ...
ELAPSED=40.02  RC=124  stderr: 0 bytes

The retry branch matches Timeout exceeded while. A killed probe writes no stderr, so it reaches
the else and sets server_died=1 on the first slow probe, which removes the property #108582
added by counting to timeouts_max=12 before declaring a hang. Turning one slow probe into an
immediate "server died" is worse than the wait this PR removes.

Row 3 also needs a peer that stalls over 30s between single bytes indefinitely. TCPHandler::sendHello
builds the whole Hello and flushes once at the closing out->next(), with each field capped at
DBMS_MAX_HELLO_STRING_SIZE 4096, and every probe here talks to the server this same script starts,
with no --host or --secure anywhere in the file. A real server either sends that payload or sends
nothing, which is rows 1 and 2.

@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6381c1822 with master ecc01ef26 (stripped binary size, per-symbol sizes and ThinLTO time; 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 705.37 MiB 702.35 MiB -3.02 MiB (-0.43%)

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

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect manual approve Manual approve required to run CI pr-ci 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