Skip to content

Fix concurrent access to enabled features in metrics forwarder - #3412

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
DataDog:mainfrom
carlosrodfern:main
Sep 1, 2026
Merged

Fix concurrent access to enabled features in metrics forwarder#3412
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
DataDog:mainfrom
carlosrodfern:main

Conversation

@carlosrodfern

@carlosrodfern carlosrodfern commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

The metrics forwarding loop could iterate over EnabledFeatures while a reconciliation updated the map, causing a fatal concurrent map iteration and map write error.

This commit clones the map under a read lock and makes the existing code iterate over the snapshot, avoiding concurrent access without holding the lock while sending metrics.

Motivation

Observed concurrent map iteration and map write errors causing the operator to crash.

Additional Notes

This fix doesn't fix the potential of map value slices concurrent modifications, however, that scenario is currently not present in the code as the values are set as whole slices and guarded by the setEnabledFeatures(..) function.

While browsing the code, I noticed that the EnabledFeatures map only holds one key, which is the id of this forwarder. This id is set only at creation time and the no longer changed. This creates an opportunity for simplification here, by turning EnabledFeatures into a slice instead.

Describe your test plan

Write there any instructions and details you may have to test your PR.

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label
  • All commits are signed (see: signing commits)

The metrics forwarding loop could iterate over EnabledFeatures while a
reconciliation updated the map, causing a fatal concurrent map iteration
and map write error.

Clone the map under a read lock and iterate over the snapshot, avoiding
concurrent access without holding the lock while sending metrics.

This fix doesn't fix the potential of map value slices concurrent
modifications, however, that scenario is currently not present in the
code as the values are set as whole slices and guarded by the
setEnabledFeatures(..) function.
@carlosrodfern
carlosrodfern requested a review from a team August 31, 2026 18:34
@tbavelier tbavelier added this to the v1.31.0 milestone Sep 1, 2026
@tbavelier tbavelier added the bug Something isn't working label Sep 1, 2026
@tbavelier

Copy link
Copy Markdown
Member

Thank you for the contribution!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants