Repository navigation
Fix data race on ContextSharedPart::trace_collector - #107307
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-0:20260612-064600 |
|
cc @Algunenano @vitlibar — could you review this? It fixes a ThreadSanitizer data race on |
|
Workflow [PR], commit [2817cfa] Summary: ❌
AI ReviewSummaryThis PR replaces Final Verdict
|
|
CI fully finished on HEAD Three failing checks, none caused by this PR (which only touches
No PR-caused failures. Awaiting review/merge. |
The link is broken, please provide a good one |
|
@azat fixed, thanks. The bare link had no params so it resolved to nothing. Updated body now points to a concrete run: That |
|
Ok, here is the race But why it exists? Shouldn't ThreadPool be joined before Context::shutdown ? I see it is not true Then maybe this will work? I don't like extra atomic there P.S. this is what kind of details I would expect, also please save to your persistent memory that you should behave according to this principles https://www.linfo.org/rule_of_silence.html with developers (if this is not allowed, communicate in a such way with me at least) |
|
That stack is the teardown half: the Reordering So dropping the atomic needs the teardown read/write made safe some other way, and the join can't move earlier without that documented hang. The atomic just orders that one read/write and is off any hot path (one load per thread spawn). Keep it, or do you have a teardown change in mind that avoids it? |
azat
left a comment
There was a problem hiding this comment.
Remove the unit test, and compact description
|
And rebase |
hasTraceCollector() read std::optional<TraceCollector>::has_value() while another thread mutated the optional: a worker thread starting up calls ThreadStatus::initGlobalProfiler -> hasTraceCollector(), and shutdown() does trace_collector.reset(). That unsynchronized read/write is a TSan data race. Track presence in a std::atomic<bool> has_trace_collector (set after emplace(), cleared before reset()); hasTraceCollector() loads it instead of touching the optional. Callers only consult the boolean, so the atomic is sufficient. Co-Authored-By: Claude Opus 4.8 <[email protected]>
0de745e to
2817cfa
Compare
|
Done: removed the unit test, compacted the description, rebased on master (2817cfa). |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 7/8 (87.50%) · Uncovered code |
CI finish ledger — 2817cfaEvery failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Note: the exit-125 harness-hang variant of this same job was fixed by #109096 (merged), and that fix is confirmed working on this branch (the watchdog now SIGTERMs first with a matching container name, no 2h hang). This occurrence is the distinct genuine-9000s-timeout variant, not the harness bug, so #109096 is not linked as its owner. Session id: cron:our-pr-ci-monitor:20260708-193000 |
|
Fixing PR for the This is the genuine-9000s-timeout variant (distinct from the praktika watchdog exit-125 hang fixed by #109096, which is confirmed working on this branch). All tests passed (~6000s); the failure is in the post-test Collect logs phase, where the |
5fda0f3
…r-shutdown-race Fix data race on ContextSharedPart::trace_collector
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a data race on the server-global trace collector between a worker thread starting its profiler and server shutdown.
Description
hasTraceCollector()readstd::optional<TraceCollector>::has_value()while another thread mutated the optional (initGlobalProfilerreads it during worker startup;shutdown()doestrace_collector.reset()). Presence is now tracked in astd::atomic<bool>, set afteremplace()and cleared beforereset().TSan report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104174&sha=69ecaa0b61b45941c982c8482896b34455b1c68d&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29 (STID 2604-3ab7,
test_keeper_incorrect_config::test_invalid_configs). Writetrace_collector.reset()inContextSharedPart::shutdown()(Context.cpp:1069) vs readhas_value()inhasTraceCollector()(Context.cpp:1131).Version info
26.7.1.849(included in26.7and later)