Skip to content

Fix PeriodicMetricReader shutdown race losing final metrics#8299

Merged
jack-berg merged 1 commit intoopen-telemetry:mainfrom
trask:metric-shutdown-race
Apr 16, 2026
Merged

Fix PeriodicMetricReader shutdown race losing final metrics#8299
jack-berg merged 1 commit intoopen-telemetry:mainfrom
trask:metric-shutdown-race

Conversation

@trask
Copy link
Copy Markdown
Member

@trask trask commented Apr 15, 2026

When a periodic export is in-flight during shutdown, doRun() sees exportAvailable=false and drops the final collection. Then exporter.shutdown() cancels the in-flight export via cancelAll().

Fix: wait for any in-flight flush to complete before the final doRun() in shutdown(). Track the in-flight flush via a volatile flushInProgress field set at the start of each doRun() cycle.

When a periodic export is in-flight during shutdown, doRun() sees
exportAvailable=false and drops the final collection. Then
exporter.shutdown() cancels the in-flight export via cancelAll().

Fix: wait for any in-flight flush to complete before the final doRun()
in shutdown(). Track the in-flight flush via a volatile
flushInProgress field set at the start of each doRun() cycle.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.26%. Comparing base (ca41b47) to head (5d499ee).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8299   +/-   ##
=========================================
  Coverage     90.25%   90.26%           
- Complexity     7683     7684    +1     
=========================================
  Files           850      850           
  Lines         23190    23193    +3     
  Branches       2353     2353           
=========================================
+ Hits          20930    20935    +5     
+ Misses         1533     1532    -1     
+ Partials        727      726    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@trask trask marked this pull request as ready for review April 16, 2026 03:00
@trask trask requested a review from a team as a code owner April 16, 2026 03:00
Copy link
Copy Markdown
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

Thanks!

@jack-berg jack-berg merged commit 65052b0 into open-telemetry:main Apr 16, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants