Skip to content

Fix 03008_deduplication_diagnostics_opt_in timeout on arm_darwin - #113980

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-03008-dedup-probe-fifo-handshake
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-03008-dedup-probe-fifo-handshake

Conversation

@groeneai

@groeneai groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Related: #112913
Related: #110202

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

...

Description

03008_deduplication_diagnostics_opt_in is killed at the 60 s per-test deadline on
Fast test (arm_darwin). No open issue tracks it; @alexey-milovidov asked me to fix it in
#110202 (comment). The test was added by
my own #112913, so this is a regression I introduced, not a pre-existing flake.

Root cause. The interrupted-rerun probe keeps its sub-probe inside the probe directory, and the stub
client waits for a go sentinel file by polling (600 iterations of 0.05 s). The driver's
wait "$int_pid" returns as soon as the run.sh shell dies from the SIGTERM, but the stub is a
grandchild and is never waited for, so the following rm -rf deletes the sentinel the live stub is
still polling for. It is created and destroyed inside one poll gap, so the stub never sees it, spins
to its cap and is left behind. That happens once per row, 12 times per run, each orphan burning 600
sleep spawns over 30 s.

This replaces both file-sentinel poll loops with blocking bounded reads on FIFOs, keeping echo go
after kill -TERM so the signal still lands inside the rerun. A FIFO write reaches the blocked
reader immediately, so the teardown can no longer strand anybody.

Measured locally, 3 runs each: orphans surviving the test 11-12 to 0, sleep spawns 1888-3686 to 0,
total execve 2897-4863 (non-deterministic) to 1189 (identical every run). Over 50 runs: reference
clean 50/50, 0 orphans, 0 sleep spawns. .reference is unchanged and the mutation arm still
reddens.

The wall-clock gain here is small (5.4 s to 4.9 s) because 96 cores absorb the spin. I have no
Darwin runner, so the arm_darwin improvement is unmeasured from here and CI on this PR is the real
measurement. I did not raise the timeout or skip the test.

The test is killed at the 60 s per-test deadline on Fast test (arm_darwin).
It was added by ClickHouse#112913, so this is a regression from that PR.

The interrupted-rerun probe keeps its sub-probe inside the probe directory,
and the stub client waits for a "go" sentinel file by polling, 600 iterations
of 0.05 s. The driver's `wait "$int_pid"` returns as soon as the run.sh shell
dies from the SIGTERM, but the stub is a grandchild and is never waited for,
so the following `rm -rf` deletes the sentinel the live stub is still polling
for. It is created and destroyed inside one poll gap, so the stub never sees
it, spins to its 30 s cap and outlives the test. That happens once per row,
12 times per run, each orphan burning 600 sleep spawns.

Replace both file-sentinel poll loops with blocking bounded reads on FIFOs.
A FIFO write reaches the blocked reader immediately and does not depend on
the file still existing when the reader next looks, so the teardown can no
longer strand anybody. Removing the polling rather than making it cheaper is
what makes the spawn count deterministic. `echo go` stays after `kill -TERM`
so the signal still lands inside the rerun. Both reads keep a 60 s timeout
with `|| true`, and both FIFO ends are held open read-write before the child
starts so neither side sees a spurious EOF.

Measured locally, 3 runs per arm: orphans surviving the test 11-12 to 0,
sleep spawns 1888-3686 to 0, total execve 2897-4863 (non-deterministic) to
1189 (identical on every run). Over 50 consecutive runs: reference clean
50/50, 0 orphans, 0 sleep spawns. The .reference file is unchanged, so every
assertion is bit-identical, and the payload oracle still reddens when
"${CASE_ARGS[@]}" is dropped from a driver's rerun line.

The wall-clock gain on a 96-core Linux box is small, 5.4 s to 4.9 s, because
the spin is absorbed there. No Darwin runner was available, so the arm_darwin
improvement is unmeasured locally. The timeout was not raised and the test
was not skipped.

Only bash 3.2 constructs are used, since arm_darwin is the target runner.
@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (1 finding, adjudicated)

Reviewed cold by a second model against the frozen PR description, then adjudicated against the
recorded evidence. One finding, plus three of my own notes.

⚠️ interrupted rerun forwards marker does not observe the handshake (test-liveness, major).
Conceded as mechanism: both read -t 60 calls end in || true, the kill/wait outcomes are not
asserted, and the row counts a marker the driver forwards before it invokes the rerun, so the row
reads 1 even if the wait declined.

DISAGREE on attribution, on three measurements:

  1. The asserted row is byte-identical on both revisions, and this change touches one file with zero
    driver files, so the forward-before-rerun ordering the finding cites as its evidence is not part
    of this diff.
  2. The same silent-pass shape is already on master: its stub polls 600 times and then exits 0
    unconditionally, and its driver proceeds whether or not the poll succeeded.
  3. Swapping echo go before kill -TERM does not redden the test, and the equivalent swap on
    pristine master does not redden it either, so the insensitivity is unchanged by this conversion.

The new shape also makes a declined wait strictly less likely: a write into a FIFO held open <> is
delivered to a reader that opens later, and survives the FIFO being unlinked, whereas the sentinel
file it replaces was the one rm -rf raced. The stub opens its read end before announcing itself,
and the driver stays blocked until that announcement, so the teardown cannot beat it.

So this is a pre-existing gap in a row the change neither touches nor weakens, and the proposed
remedy would change .reference and widen a cost-only fix. Recorded here rather than fixed, and I
am not opening a follow-up: nothing about it is reachable by a user, and it has never hidden a real
failure.

💡 My own notes (no change): this becomes the first mkfifo user under
tests/queries/0_stateless that actually runs on Fast test, since the other three are no-fasttest
or long; the primitives are POSIX and bash 3.2 safe, with the same exec {fd}<> idiom already in
streaming.lib. The driver-side cap widens from 10 s to 60 s, which cannot change a verdict because
12 rows exceed the 60 s per-test deadline either way. I also dropped a duplicated Related: pair
from the description.

Session id: cron:clickhouse-review-slot-8:20260808-194200

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. bash tests/queries/0_stateless/03008_deduplication_diagnostics_opt_in.sh then counting surviving stub processes (pgrep -f "[c]lient_block", with a /proc/<pid>/exe guard) shows 11-12 orphans on every pre-fix run (3 of 3), and a straced run shows non-deterministic sleep spawns (1888 / 1890 / 3686). Not a rare flake: the defect fires 12 times per run, every run. No server is needed.
b Root cause explained? Yes. The interrupt sub-probe lives inside the probe directory. The stub client waits for a go sentinel FILE by polling (600 iterations of 0.05 s). The driver's wait "$int_pid" returns as soon as the run.sh shell dies from the SIGTERM, but the stub is a grandchild and is never waited for, so the following rm -rf deletes $I/go inside one 0.05 s poll gap. The stub never observes the sentinel, spins to its 30 s cap and outlives the test, once per row. Darwin process creation is far more expensive than Linux, and the runner already averages 46.3 s against a 60 s deadline, so that is where it crosses.
c Fix matches root cause? Yes. The defect is that the handshake token is a file whose lifetime is coupled to the directory the test deletes. Both file-sentinel poll loops become blocking bounded reads on FIFOs, so the token reaches the blocked reader immediately and cannot be deleted out from under it. Polling is removed rather than shortened, so the cost becomes deterministic by construction. Not a timeout bump, not no-fasttest, not ci/defs/darwin.skip, and not a sleep-before-rm -rf timing guess.
d Test intent preserved / new tests added? Yes. .reference is byte-unchanged (279 lines, empty diff), so every assertion is bit-identical. The interrupt probe still SIGTERMs the rerun in flight and still asserts the marker was forwarded (12 rows, all 1); echo go stays after kill -TERM so the signal still lands inside the rerun. The changed file IS the test, so no new test is owed. The mandatory mutation arm confirms the payload oracle still reddens: dropping "${CASE_ARGS[@]}" from a driver's rerun line flips the payload-equality rows from 1 to 0.
e Both directions demonstrated? Yes, 3 runs per arm in each of two measurement modes. Pre-fix: 11 / 12 / 12 orphans, sleep spawns 1888-3686, execve 3065-4863 non-deterministic. With the fix: 0 / 0 / 0 orphans, 0 sleep spawns, execve exactly 1189 on every run. Reference clean in all arms. Over 50 consecutive runs with the fix: 50/50 pass, 0 orphans, 0 sleep spawns. Orphans must be counted on an unstraced run, since strace stretches the run past the 30 s spin and the count then reads a misleading 0 on the pre-fix arm too.
f Fix is general across code paths? Yes. Both file-sentinel poll loops are converted, not only the defective one: the stub's go loop (the bug) and the driver's rerun_started loop (same anti-pattern and cap, stable today only because nothing deletes its file underneath it). Converting both is what takes sleep to exactly 0. The third candidate, the returning stub, has no wait loop at all (writes its payload and exits), so there is nothing to convert. The now-dead rerun_started write is removed; a tree-wide grep confirmed the replaced loop was its only reader.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for type wrappers: this is a shell-level test-harness change with no SQL or type surface. The relevant input axis is the driver x phase matrix, and the fix applies identically to all 12 iterations (6 drivers x 2 phases) with all 12 marker rows staying 1. Adverse cases are covered: both reads carry -t 60 with `
h Backward compatible? (maintainer-approved exception only) Yes, trivially. Test-only change: no setting, no default, no SettingsChangesHistory.cpp, no serialization or format change, no config, nothing under src/.
i Invariants and contracts preserved? Yes. Invariant established: the handshake completes before the probe directory is removed, and no probe process outlives the test (0 orphans over 50 runs). rm -rf "$W" is unchanged and now safe by construction. Verified after the final run that no 03008_dedup_probe_* directory and no dangling FIFO remain under $CLICKHOUSE_TMP, so the FIFOs do not leak and nothing holds the directory open. Error paths: the -t 60 plus `

Session id: cron:clickhouse-impl-slot-7:20260808-174300

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CheSema, could you review this? The interrupted-rerun probe in this test waited on a sentinel file that its own rm -rf teardown deleted out from under the still-polling stub, leaving 12 spinning processes per run, and this replaces both sentinel poll loops with blocking reads on FIFOs so the token cannot be deleted before the reader sees it.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3c73f6c]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
02458_relax_too_many_parts FAIL cidb

AI Review

Summary

This PR converts the interrupted-rerun probe in 03008_deduplication_diagnostics_opt_in.sh from file-sentinel polling to FIFO handshakes so the test no longer leaves behind polling grandchildren that can push Fast test (arm_darwin) into the per-test timeout. I found no new correctness or portability issues in the changed code, and the relevant CI job is green.

Missing context / blind spots
  • ⚠️ A local standalone run of 03008_deduplication_diagnostics_opt_in.sh was not authoritative because this checkout does not provide a working clickhouse-format binary ($CLICKHOUSE_FORMAT resolves to -format), so six untouched emit parses rows fail before the touched FIFO path can be used as clean local regression evidence. I therefore relied on code inspection plus the green PR CI signal for the final verdict.
Final Verdict

✅ No actionable findings.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3c73f6c

CI is fully finished on this head: 175 check-runs, 0 queued/in progress, Finish Workflow completed. Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 02458_relax_too_many_parts pre-existing trunk regression: TOO_MANY_PARTS (Code 252) thrown by the plain-INSERT fan-out path; 61 rows / 57 PRs / 4 master in 30d. The job's own randomized-settings diagnosis re-ran it 150 times with 0 failures, so it is not settings-dependent #113045 (external, open)

Build (arm_release) / Post Hooks also carries a CIDB row, but that job completed successfully - the row is the build-profile hook's LogCluster query failed with code 500, which does not fail the check. Not a red, so no owner is owed. The single change in this PR is one line in tests/queries/0_stateless/03008_deduplication_diagnostics_opt_in.sh, which is untouched by the failure above.

Session id: cron:our-pr-ci-monitor:20260809-023000

@fm4v

fm4v commented Nov 19, 2026

Copy link
Copy Markdown
Member

Closing as obsolete: the arm_darwin timeout was fixed by #114005, which moved the stub-client replay into 03008_deduplication_diagnostics_replay.sh and skipped it on darwin. The code this PR edits no longer exists, and 03008_deduplication_diagnostics* has not failed in the last 30 days. The orphan sleep cleanup could be redone against 03008_deduplication_diagnostics_replay.sh if still wanted.

@fm4v fm4v closed this Nov 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-materialized-view Materialized views: insert-triggered MV pipeline, insert dependencies, deduplication. and removed comp-testing Test content only (no production code). labels Nov 22, 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-materialized-view Materialized views: insert-triggered MV pipeline, insert dependencies, deduplication. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants