Skip to content

[Exporter.Prometheus] Fix concurrency issue - #7571

Merged
martincostello merged 4 commits into
open-telemetry:mainfrom
martincostello:fix-flaky-test
Aug 4, 2026
Merged

martincostello merged 4 commits into
open-telemetry:mainfrom
martincostello:fix-flaky-test

Conversation

@martincostello

@martincostello martincostello commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Changes

Fix concurrency issue introduced by the fix in #7524. Now, instead of retrying under failed scrapes under contention, instead return an error.

A first attempt at fixing the issue made things work by introducing a deadlock, and the original fix that created this secondary issue was for a stack overflow, so at this point it's probably safer to fail faster if under high contention (which realistically shouldn't happen to a scrape endpoint?) and let the client itself retry.

Detected by test flakiness in #6899. This job took 6 attempts to pass - for some reason the bug is more apparent only when running under .NET 11.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Fix concurrency issue introduced by the fix in open-telemetry#7524.
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package labels Jul 29, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-08-04 12:10 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.43590% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.67%. Comparing base (53af110) to head (7b74c73).
⚠️ Report is 9 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ner/Internal/Shared/PrometheusCollectionManager.cs 97.43% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7571      +/-   ##
==========================================
+ Coverage   90.44%   90.67%   +0.22%     
==========================================
  Files         290      290              
  Lines       15989    16434     +445     
==========================================
+ Hits        14462    14901     +439     
- Misses       1527     1533       +6     
Flag Coverage Δ
unittests-Project-Experimental 90.59% <97.43%> (+0.06%) ⬆️
unittests-Project-Stable 90.49% <97.43%> (+0.02%) ⬆️
unittests-UnstableCoreLibraries-Experimental 51.35% <97.43%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ner/Internal/Shared/PrometheusCollectionManager.cs 90.61% <97.43%> (-0.07%) ⬇️

... and 10 files with indirect coverage changes

The previous fix introduced a deadlock - instead, remove the retries and return an error instead.
@martincostello
martincostello marked this pull request as ready for review July 29, 2026 16:37
@martincostello
martincostello requested a review from a team as a code owner July 29, 2026 16:37
Copilot AI review requested due to automatic review settings July 29, 2026 16:37

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

This pull request updates the Prometheus exporter scrape/collection coordination to avoid pathological retry behavior under contention. It changes the PrometheusCollectionManager so that scrapes which shared a collection that ultimately failed will also fail (rather than retrying and potentially stalling), and updates the associated unit test and package changelogs.

Changes:

  • Change PrometheusCollectionManager to return a failed CollectionResponse when a scrape joined a collection that produced no response for its protocol, instead of retrying.
  • Update the concurrency unit test to assert that all scrapes sharing a failed collection report failure (and that the collection is not re-run on their behalf).
  • Add CHANGELOG entries for both Prometheus exporter packages.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs Updates concurrency test to validate “fail-fast” behavior for scrapes sharing a failed collection.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusCollectionManager.cs Adjusts retry/failure logic in WaitForCollectionResponseAsync to avoid retrying after a shared failed collection.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Adds an Unreleased entry describing the behavior change.
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Adds an Unreleased entry describing the behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Remove spinning to avoid additional contention issues.
- Fix flaky test by ensuring there are enough free threads.

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 5 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs:304

  • This new deadlock-regression test can hang indefinitely if EnterCollect regresses to synchronously blocking while waiting for active readers (the call to EnterCollectAsync is made on the same thread that is holding a reader slot). Add an explicit xUnit timeout so the suite fails fast instead of stalling CI when the regression reproduces.
    [Fact]

Refactor test to avoid hang in CI if there is a regression.
This was referenced Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants