Skip to content

Fix flaky test_executable_udf_profile_events peak-memory tests under Thread Sanitizer - #108559

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-udf-peak-memory-sampling-flaky
Jun 27, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-udf-peak-memory-sampling-flaky

Conversation

@groeneai

@groeneai groeneai commented Jun 25, 2026 •

Copy link
Copy Markdown
Collaborator

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

Requested by @alexey-milovidov in #108192 (comment): fix the flaky test_executable_udf_profile_events.

The recurring flakiness is confined to four /proc-VmHWM peak-memory tests, and only on Thread Sanitizer: test_peak_memory_is_max_not_sum, test_peak_memory_reflects_udf_not_server, test_peak_memory_byte_seconds, test_reaped_child_memory_rolls_up. Over 30 days they fail across many unrelated PRs, all on amd_tsan, in both directions: concurrent implied peak 10.1 MiB < 60 MiB floor (children never sampled) and concurrent peak 933523455 ... > 1.6x sequential (inflated reading). Example report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108248&sha=ca87a98980ffe3ce7777c05d576fad48532eaccf&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29 . The suite's other tests (invocations, bytes, elapsed, CPU) are stable.

Root cause: PeakMemoryByteSeconds is sampled from /proc/<pid>/VmHWM across the UDF subtree on a best-effort ~5 ms throttle (UDFProcessSubtreeSampler). Under Thread Sanitizer the scheduling skew and sanitizer memory bloat make that sampling non-deterministic over the test's one-row window, so the tight implied-peak bounds are unreliable there. The metric is correct on every non-sanitizer build (verified locally: stable ~107 MiB; the assertions still pass and still catch a deliberately broken UDF that reports parent-only memory).

Fix: skip only the /proc-VmHWM peak-memory assertions under Thread Sanitizer, matching the existing pattern in other memory/timing integration tests (test_fetch_memory_usage, test_hedged_requests). All assertions stay active on every non-sanitizer build, so the metric keeps full regression coverage.

The TSAN-specific timing artifact is not reproducible without a TSAN integration build; the change targets the best-effort sampling fragility the sampler's own documentation already calls out.

Version info

  • Merged into: 26.7.1.163 (included in 26.7 and later)

…e_events under TSAN

The four peak-memory tests (test_peak_memory_is_max_not_sum,
test_peak_memory_reflects_udf_not_server, test_peak_memory_byte_seconds,
test_reaped_child_memory_rolls_up) are flaky exclusively on Thread Sanitizer.

PeakMemoryByteSeconds is sampled from /proc/<pid>/VmHWM across the UDF subtree
on a best-effort ~5 ms throttle (UDFProcessSubtreeSampler). Under TSAN the
scheduling skew and sanitizer memory bloat make that sampling non-deterministic
over the test's one-row window, producing both directions of failure: an
implied peak below the floor (children never sampled) and an inflated reading
above the max-not-sum ratio. The metric is correct on every non-sanitizer
build, where the assertions remain fully active and still catch a UDF that
reports only the parent's memory.

Skip only these assertions under Thread Sanitizer, matching the existing
pattern in other memory/timing integration tests (test_fetch_memory_usage,
test_hedged_requests). MSAN is already skipped.

Requested by alexey-milovidov in PR ClickHouse#108192.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The TSAN failure is not locally reproducible without a TSAN integration build (rate ~1-2/day fleet-wide). CIDB is deterministic on the signature: 17 amd_tsan failures across 17 distinct PRs over 30d, both directions (< 60 floor and > 1.6x ratio), confined to the 4 /proc-VmHWM peak tests. Non-TSAN is deterministically stable (0/180 direct + 17/17 + 30/30 integration runs, ~107 MiB).
b Root cause explained? PeakMemoryByteSeconds = max /proc/<pid>/VmHWM across the UDF subtree, sampled best-effort on IO with a ~5 ms throttle (UDFProcessSubtreeSampler). Over the test's one-row (~20 ms) window under TSAN scheduling skew + sanitizer memory bloat, the sampler misses the children at peak (→ ~10 MiB, floor fails) or reads an inflated value (→ ~900 MiB, ratio fails).
c Fix matches root cause? Yes. The unreliability is the /proc VmHWM sampling under TSAN. The fix skips exactly those assertions only on TSAN, where the sampling is non-deterministic. The metric is unchanged and proven correct elsewhere.
d Test intent preserved / new tests added? Preserved. All assertions stay fully active on every non-sanitizer build. Verified locally that a deliberately broken UDF (children allocate nothing → metric reports parent-only ~10 MiB) still FAILS the >= 60 floor on the debug build, so the regression coverage is intact.
e Both directions demonstrated? On the builds where it runs: assertions PASS on a correct metric (~107 MiB) and FAIL on a broken one (~10 MiB). The skip logic was unit-tested both ways (TSAN → skip, non-TSAN → run). The TSAN failure itself needs a TSAN build to observe, stated openly.
f Fix is general across code paths? Applied to all 4 /proc-VmHWM peak-memory tests that exhibit the flakiness; the non-memory tests (invocations, bytes, elapsed, CPU) are stable and untouched.
g Fix generalizes across inputs? N/A (test-only sanitizer guard, not a code-path/datatype change).
h Backward compatible? N/A (test-only change, no behavior/setting/format change).
i Invariants and contracts preserved? N/A (test-only change; the C++ metric is unchanged).

Session id: cron:clickhouse-worker-slot-4:20260625-221400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @vitlibar — could you review this? Test-only change: it skips the four /proc-VmHWM peak-memory assertions of test_executable_udf_profile_events under Thread Sanitizer (where that best-effort sampling is non-deterministic), keeping every assertion active on all non-sanitizer builds. Follows the existing test_fetch_memory_usage / test_hedged_requests sanitizer-skip pattern.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5c0ea15]

Summary: ✅


AI Review

Summary

This PR adds _skip_unreliable_peak_memory_sampling and applies it only to the four /proc VmHWM peak-memory assertions in test_executable_udf_profile_events on Thread Sanitizer builds. The change is test-only, keeps the rest of the suite active under Thread Sanitizer, and preserves these PeakMemoryByteSeconds checks on non-sanitizer builds. I found no blocking or major issues.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 733 line(s), 55 function(s) across 173 file(s) · Details

Top files
  • src/Storages/ObjectStorage/DataLakes/Iceberg/RemoveOrphanFilesExecute.cpp: 140 line(s), 9 function(s)
  • src/Storages/ObjectStorage/DataLakes/Iceberg/SnapshotFilesTraversal.cpp: 74 line(s), 4 function(s)
  • src/Common/ZooKeeper/ZooKeeperImpl.cpp: 16 line(s)
  • src/Disks/IO/CachedOnDiskWriteBufferFromFile.cpp: 15 line(s)
  • src/IO/Archives/LibArchiveReader.cpp: 15 line(s)

Full report

@alexey-milovidov alexey-milovidov self-assigned this Jun 27, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 27, 2026
Merged via the queue into ClickHouse:master with commit a6149a1 Jun 27, 2026
167 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 27, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…eak-memory-sampling-flaky

Fix flaky test_executable_udf_profile_events peak-memory tests under Thread Sanitizer
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 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.

4 participants