Skip to content

Do not abort run-fuzzer.sh when the fuzzer client exits before its PID is found - #129073

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-run-fuzzer-client-pid-race
Nov 4, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-run-fuzzer-client-pid-race

Conversation

@groeneai

@groeneai groeneai commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #129033

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):

The AST fuzzer job no longer reports error when a fuzzer pass finishes before the runner finds the client's PID.

Description

Targeted AST fuzzer jobs report error with Fuzzer runner aborted before writing status.tsv although the fuzzer found nothing, e.g. #129033 and this job. 7 such jobs on 3 PRs since 2026-10-04, all adding an access type, so their corpus is the single SHOW PRIVILEGES of 01271_show_privileges.

run-fuzzer.sh restarts the client on exit 0 until the budget is used, so such a job runs many passes (162 in one job). After polling for the clickhouse-client that timeout starts, the script read its PID a second time, outside any condition. If the client had already exited, ps returned 1 and set -e killed the script before status.tsv was written. Without gdb attached, a SHOW PRIVILEGES pass takes 17 ms on the server, under one 0.1 s poll interval. In the CI logs, either all 50 polls printed Not found, or a poll found the client and the second read did not.

Now the poll that finds the PID keeps and logs it, and the second read is removed. The client gdb attach is skipped only when no PID was found, and the poll stops once timeout itself has exited instead of polling for 5 s. wait still returns the client's exit code, so restart and failure handling are unchanged.

Validation: I ran the old and new pass block with stub clickhouse-client, gdb and ps. The old one aborts with the CI trace in three cases: ps never finds the client, finds it only once, or the client exits with code 3. The new one completes and keeps exit code 3. With the real ps and an instantly exiting client, the old block aborts 200/200 and the new one 0/200, and its pass block now takes under 0.5 s instead of 5 s. A client that runs 3 s, or that ps sees only after 10 polls, still gets gdb attached.


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

Version info

  • Merged into: 26.11.1.1336-master (included in 26.11 and later)

…ID is read

run-fuzzer.sh polls `ps -o pid= --ppid <timeout pid>` to find the
clickhouse-client started by `timeout`, then read the PID a second time
outside any condition. `ps` exits 1 when `timeout` has no child, and under
`set -e` that failing command substitution killed the script before
status.tsv was written, so the job reported `error` although the fuzzer
found nothing.

The runner restarts the client on exit 0 to use the whole time budget, so a
targeted job over a tiny corpus (a single `SHOW PRIVILEGES`, which is the
corpus of every PR that adds an access type) runs 20-160 passes, and without
gdb attached a pass can end before a poll finds the client. Two shapes were
seen in CI: the client exited before any poll found it (all 50 polls print
`Not found`), or it exited between the poll that found it and the second read.

Capture the PID in the polling condition, drop the second read, and skip the
client gdb attach when no PID was found. `wait` on the timeout process still
returns the client's real exit code, so the restart/stop logic is unchanged.

Failing jobs:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129033&sha=848480638bef900cfb5b8109c68b330e693c734a&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123854&sha=b6b8aa5f6f4159160d2ff95fb1799f10e7fbd20d&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: 0 findings open

Cold review and Gate B of head 43855ce02623: no blocker or major findings.

Finding Verdict
💡 The skip line says the client "exited" although the only observable is that ps found no child of timeout noted, not blocking: every measured way to reach it (6 CI job logs, the local race runs) is an exited client; nothing parses the line

@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The pass block extracted from the old script, run with stub clickhouse-client/gdb/ps, aborts with the CI trace (+ actual_fuzzer_pid=) when ps never finds the client and when it finds it only once. With the real ps and a client that exits at once it aborts 200/200.
b Root cause explained? After the poll loop the script read the client PID a second time outside any condition. Once the client has exited, ps --ppid returns 1 and set -e kills fuzz() before status.tsv is written. A SHOW PRIVILEGES pass without gdb lasts 17 ms on the server, less than one poll interval.
c Fix matches root cause? Yes. The second read is removed and the poll's own result is reused; the gdb attach is skipped only when no PID was found. No sleeps, retries or timeouts changed.
d Test intent preserved / new tests added? Test-infrastructure change, so no harness self-test ships (#119766). Validated locally with the A/B harness above; gdb still attaches to a live client.
e Both directions demonstrated? Yes. Never-found, found-once and exit-code-3 cases fail on the old block and pass on the new one (exit code 3 preserved); real-ps race 200/200 aborts vs 0/200.
f Fix is general across code paths? It is the only PID lookup in the tree; BuzzHouse runs the same block. The other set -e exits in fuzz() fire only when the server never started, which is a real failure the job reports.
g Fix generalizes across inputs (params/datatypes/wrappers)? Covered every ps outcome (never found, found then gone, found and alive) and client exit codes 0 and 3. The space-padded PID from ps attaches correctly. The ASAN branch is unchanged.
h Backward compatible? (maintainer-approved exception only) Yes. CI shell script only; one new log line, which nothing parses.
i Invariants and contracts preserved? A finished client no longer aborts the runner; gdb attaches whenever the client was alive when found; wait still feeds the real exit code to the restart/stop logic; actual_fuzzer_pid is set before use under set -u.

Session id: cron:clickhouse-impl-slot-6:20261103-172600

@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this and add the can be tested label so CI runs? After polling for the fuzzer client, run-fuzzer.sh read its PID a second time outside any condition, so when a short targeted pass had already exited, ps returned 1 and set -e killed the job before status.tsv was written; the PID found by the poll is now reused and gdb is skipped only when none was found.

@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [326f29d]

Summary: ✅


AI Review

Summary

The PR prevents run-fuzzer.sh from aborting when a short fuzzer pass exits during PID discovery. It reuses the discovered PID and stops polling after timeout exits. No actionable findings at head 326f29d1a04af52e2671f99001fa3b700aa8d2fa. Focused validation reproduced both original failure modes and passed all 11 cases, including client exit-code preservation, delayed discovery, and the ASan path.

Missing context / blind spots
  • ⚠️ Full AST-fuzzer CI jobs were pending in the fetched report. Local checks used real processes and deterministic stubs, with debugger invocation stubbed; successful current-head fuzzer jobs would close the end-to-end validation gap.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). can be tested Allows running workflows for external contributors labels Nov 3, 2026
@PedroTadim PedroTadim self-assigned this Nov 3, 2026
@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai

The fix is right. The second ps was the only command in the pass that could fail under set -e after the client was gone. Keeping the PID from the poll that found it removes both failure shapes in the CI logs. Two other things also hold:

  • wait "$fuzzer_pid" still waits on timeout, so fuzzer_exit_code and the restart logic are unchanged.
  • actual_fuzzer_pid is not used anywhere else in the script.

Two small, optional points:

  1. The PID is no longer in the log. Before, the successful ps printed the PID just before Found underlying PID!. Now it is captured, so the log has the message without the number. echo "Found underlying PID $actual_fuzzer_pid" would keep it, which helps when matching a gdb or sanitizer trace to its pass.

  2. A pass whose client exits before the first poll now costs 5 s of polling. Once the client is gone, ps --ppid finds nothing all 50 times. With a one-query corpus and hundreds of passes, those 5 s add up. Stopping the poll once timeout itself has exited would make such passes immediate. kill -0 does not work for that, because timeout is a zombie until wait. Checking ps -o stat= -p "$fuzzer_pid" for Z does. That is only time spent, not a wrong result, so a follow-up is fine too.

Review on ClickHouse#129073: print the PID found by the poll again (the second `ps`
used to print it), and do not spend the whole 5 s poll on a pass whose
client is already gone.

bash reaps the background `timeout` as soon as it exits and keeps its status
for `wait`, so `kill -0` on it fails from the next poll on (measured in the
clickhouse/fuzzer image, bash 5.2.21: `ps -o stat= -p` is already empty, it is
not a zombie). Such a pass now leaves the poll after at most one retry instead
of 50, and `wait` still returns the client's exit code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Nov 3, 2026
@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, both are in 326f29d:

  1. The poll that finds the client now prints Found underlying PID <pid>.
  2. The poll stops once timeout has exited. I used kill -0 for it: bash reaps the background timeout as soon as it exits and keeps its status for wait, so it does not stay a zombie. Measured in the clickhouse/fuzzer image (bash 5.2.21): on the first poll after timeout exits, ps -o stat= -p is already empty and kill -0 fails, and wait still returns the exit code, so a Z check would never fire. With a client that exits at once, the pass block now takes under 0.5 s instead of 50 polls (100/100 runs), and a client that ps sees only after 10 polls still gets gdb attached.

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 4, 2026
Merged via the queue into ClickHouse:master with commit b51e7ac Nov 4, 2026
185 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 4, 2026
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 comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). 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