Repository navigation
Bound the AST fuzzer liveness probes and teardown diagnostics - #115915
alexey-milovidov merged 1 commit into
Conversation
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.
Internal second-model review (click to expand)Two review rounds before this was published; the second model reported no findings on the Fixed:
Checked and left alone:
One point worth stating because it is stronger than the margin argument in the description: Session id: cron:clickhouse-review-slot-11:20260822-132300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260822-073900 |
|
Workflow [PR], commit [6381c18] Summary: ✅ AI ReviewSummaryThis PR reduces several long waits in Findings
Final VerdictRequest changes: the probe path still lacks a hard wall-clock deadline, so the runner-time bound this PR promises is not yet guaranteed. |
|
cc @PedroTadim, could you review this? The post-fuzz liveness probe loop in |
| # --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 |
There was a problem hiding this comment.
--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.
There was a problem hiding this comment.
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.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
e8d0bec
---8<--- PR BODY BELOW (first line above is the intended title) ---8<---
Changelog category (leave one):
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_timeoutis inert until the handshake completes.Connection.cpp:319-320puts both socket timeouts on
handshake_timeoutbeforesendHelloandonly 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 thataccepts TCP but never finishes the handshake never reaches the 5 second bound. Against a listener
that accepts and never replies,
--receive_timeout=5alone blocks 300 s (322 s over TLS, thefuzzer's port, where the message reads "writing to socket" and misattributes to
send_timeout);--handshake_timeout_ms=30000bounds it at 30 s, and 5000 and 12000 confirm the bound tracks thevalue passed.
Four probes therefore get one extra token, and the two best-effort diagnostics get a hard command
deadline,
--kill-afterincluded because a baretimeoutwaits indefinitely for a child ignoringSIGTERM (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
7ec04d1132644a7documents a healthy server needingover 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]