Repository navigation
[Exporter.Prometheus] Fix stack overflow - #7524
martincostello merged 4 commits into
Conversation
Fix stack overflow caused by recursion if `EnterCollect()` failed and then completed synchronously introduced by refactoring in open-telemetry#7371.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7524 +/- ##
=======================================
Coverage 90.23% 90.23%
=======================================
Files 290 290
Lines 15936 15967 +31
=======================================
+ Hits 14380 14408 +28
- Misses 1556 1559 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a stack overflow in the Prometheus exporter scrape path by eliminating recursive retry behavior when a shared collection completes synchronously but does not produce a response for the requested protocol. It introduces bounded retry loops and adds a stress-style regression test to validate the retry path under contention.
Changes:
- Refactors
PrometheusCollectionManager.EnterCollect/WaitForCollectionResponseAsyncto use bounded loops instead of recursion when retrying after a shared collection doesn’t satisfy a protocol. - Adds a
MaxCollectAttemptscap and aCollectStepresult type to make retry behavior explicit and prevent infinite retry/starvation. - Adds a regression test that repeatedly exercises the retry path under concurrent scraping to ensure it does not overflow the stack.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusCollectionManager.cs |
Reworks collection entry/retry logic to avoid recursive retries (stack growth) and adds bounded retry limits. |
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs |
Adds a contention-based regression test to ensure retry behavior doesn’t overflow the stack. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot review feedback.
|
|
||
| if (!resolved) | ||
| { | ||
| // The attempt budget was exhausted while contending with concurrent |
There was a problem hiding this comment.
Should a warning be emitted in this case?
There was a problem hiding this comment.
These are both just constructs to avoid using a while (true) in case there was ever a logic bug that meant the loop never terminated, but it shouldn't happen.
There was a problem hiding this comment.
Added a log message for completeness just in case.
| } | ||
|
|
||
| if (protocolWasRegistered) | ||
| // The retry budget was exhausted while contending with concurrent scrapes; |
There was a problem hiding this comment.
Similar situation - worth emitting a warning here? Or is this a typical situation?
There was a problem hiding this comment.
Added a log message for completeness just in case.
Add an error log if the collection cannot acquire a lock to get a response within the retry budget for some reason.
Add entries for this PR.
Changes
Fix stack overflow caused by recursion if
EnterCollect()failed and then completed synchronously introduced by refactoring in #7371.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)