Skip to content

Fix data race when tracing profile events - #113553

Merged
mstetsyuk merged 6 commits into
masterfrom
profile-events-should-trace-array-acquire
Aug 19, 2026
Merged

mstetsyuk merged 6 commits into
masterfrom
profile-events-should-trace-array-acquire

Conversation

@mstetsyuk

@mstetsyuk mstetsyuk commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix a theoretical data race in profile events when using the trace_profile_events_list setting to write stack traces of certain profile events to system.trace_log.

Version info

  • Merged into: 26.8.1.1710 (included in 26.8 and later)
  • Backported to: 26.7.5.4

@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [49bcc3d]

Summary: ❌

job_name test_name status info comment
Bugfix validation (unit tests) FAIL
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL

AI Review

Summary

This PR hardens ProfileEvents::Counters by publishing the lazily allocated should_trace_array with acquire-release semantics and by adding a focused gtest for concurrent setTraceProfileEvent / increment. The synchronization change is consistent across the publication, read, and move paths, and the current PR state does not show any blocking code issues.

PR Metadata
  • 💡 Changelog category is too strong. This is a tracing correctness fix, but it does not match the template's Critical Bug Fix (crash, data loss, RBAC) bucket.
  • Suggested replacement: Bug Fix
  • The Changelog entry itself is specific and user-readable as written.
Final Verdict

✅ No blocking code findings. Update the Changelog category from Critical Bug Fix to Bug Fix.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

Changed lines: Changed C/C++ lines covered: 29/29 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Aug 5, 2026
Comment thread src/Common/ProfileEvents.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 49bcc3d18 with master 6bd0d202a (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 91b700711; 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 692.09 MiB 689.08 MiB -3.01 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

8 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

@mstetsyuk

Copy link
Copy Markdown
Member Author

Same as in #112466, the bugfix validation check only builds the before build with UB + Address sanitizers - and to catch this bug we need TSan. I've verified 50/50 red before, 50/50 green after with TSan manually.

…ld-trace-array-acquire

# Conflicts:
#	src/Common/ProfileEvents.cpp
#	src/Common/tests/gtest_profile_events.cpp
if (current->should_trace_array.load(std::memory_order_relaxed))
{
if (auto * trace_arr = current->should_trace_array.load(std::memory_order_acquire))
send_to_trace_log |= trace_arr[event].load(std::memory_order_relaxed);

@Michicosun Michicosun Aug 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

datarace on trace_arr deref

just for other readers

@mstetsyuk
mstetsyuk added this pull request to the merge queue Aug 19, 2026
Merged via the queue into master with commit f2f01c9 Aug 19, 2026
178 of 181 checks passed
@mstetsyuk
mstetsyuk deleted the profile-events-should-trace-array-acquire branch August 19, 2026 18:35
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 19, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 19, 2026
Backport #113553 to 26.7: Fix data race when tracing profile events
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants