Fix records_yaml startup lookup race - #13538
Open
bneradt wants to merge 2 commits into
Open
Conversation
The records_yaml AuTest intermittently reported that proxy.config.diags.output.note was missing when a configuration callback ran while startup was still registering metrics. Metrics::find() returned the then-current end iterator for a miss, but RecLookupRecord() compared it with a new end iterator. An intervening registration made them differ and misread the missing string record as a numeric metric. This patch addresses the race by using the direct metrics lookup API, which reports a miss without comparing two moving end positions. It also adds a concurrent registration test that exercises string record lookups during metric creation.
The macOS CI toolchain does not provide std::jthread, which prevents test_records from compiling before the regression test can run. This uses std::thread instead. The test already joins the worker explicitly, so its behavior and lifetime remain unchanged.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/records/unit_tests/test_RecRegister.cc:122
- The concurrency test currently (a) spins in a tight loop waiting for
start, and (b) allocates 100k uniquely-named metrics (strings + lookup-table entries) that can’t be cleaned up and will bloat the test process for the remainder of the suite. You can avoid the CPU spin by usingstd::atomic::wait/notify_one, and you can advance the Metrics insertion position without allocating unique names by usingts::Metrics::Counter::createSpan(1)inside the registration loop.
std::atomic<bool> start{false};
std::atomic<bool> finished{false};
std::thread register_metrics([&]() {
while (!start.load(std::memory_order_acquire)) {
std::this_thread::yield();
JosiahWI
requested changes
Aug 12, 2026
JosiahWI
left a comment
Contributor
There was a problem hiding this comment.
The fix is good. I have a request for clarification on the concurrency test.
Comment on lines
+20
to
+22
| #include <atomic> | ||
| #include <string> | ||
| #include <thread> |
Contributor
There was a problem hiding this comment.
Nit: it's better to include standard headers after local project headers to expose missing includes quickly.
Comment on lines
+123
to
+129
| while (!finished.load(std::memory_order_acquire)) { | ||
| if (RecGetRecordStringAlloc(record_name) != record_value) { | ||
| all_lookups_succeeded = false; | ||
| break; | ||
| } | ||
| ++lookup_count; | ||
| } |
Contributor
There was a problem hiding this comment.
This loop can run 0 times in theory, which will fail the test. What was the intent here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The records_yaml AuTest intermittently reported that
proxy.config.diags.output.note was missing when a configuration
callback ran while startup was still registering metrics.
Metrics::find() returned the then-current end iterator for a miss, but
RecLookupRecord() compared it with a new end iterator. An intervening
registration made them differ and misread the missing string record as
a numeric metric.
This patch addresses the race by using the direct metrics lookup API,
which reports a miss without comparing two moving end positions. It also
adds a concurrent registration test that exercises string record lookups
during metric creation.