Skip to content

Fix records_yaml startup lookup race - #13538

Open
bneradt wants to merge 2 commits into
apache:masterfrom
bneradt:fix-records-yaml-flake
Open

Fix records_yaml startup lookup race#13538
bneradt wants to merge 2 commits into
apache:masterfrom
bneradt:fix-records-yaml-flake

Conversation

@bneradt

@bneradt bneradt commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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 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.
@bneradt bneradt added this to the 11.0.0 milestone Aug 12, 2026
Copilot AI lite review requested due to automatic review settings August 12, 2026 01:06
@bneradt bneradt self-assigned this Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.
Copilot AI review requested due to automatic review settings August 12, 2026 02:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 using std::atomic::wait/notify_one, and you can advance the Metrics insertion position without allocating unique names by using ts::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 JosiahWI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This loop can run 0 times in theory, which will fail the test. What was the intent here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants