[SDK] Add destructor to PeriodicExportingMetricReader to fix shutdown race - #4008
Merged
marcalff merged 7 commits intoApr 20, 2026
Merged
Conversation
… race Destroying a PeriodicExportingMetricReader without calling Shutdown() leaves the background worker thread running inside cv_.wait_for() while the mutex and condition variable members are destroyed. This causes a use-after-destroy race detected by ThreadSanitizer. Add an explicit destructor that calls Shutdown() and joins the worker thread before member destruction, matching the pattern already used by BatchSpanProcessor and BatchLogRecordProcessor. Add a DestroyWithoutShutdown test to verify safe destruction without an explicit Shutdown() call.
jnillius
force-pushed
the
fix/periodic-metric-reader-destructor
branch
from
April 16, 2026 13:51
d2f7139 to
19f4a24
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4008 +/- ##
==========================================
+ Coverage 90.32% 90.34% +0.02%
==========================================
Files 230 230
Lines 7299 7303 +4
==========================================
+ Hits 6592 6597 +5
+ Misses 707 706 -1
🚀 New features to boost your workflow:
|
Member
|
Thanks for the bug report and fix. Please sign the EasyCLA, and fix clang-format. |
dbarker
reviewed
Apr 16, 2026
dbarker
left a comment
Member
There was a problem hiding this comment.
Good catch! Thanks for the PR. Please see feedback below on some minor points.
Contributor
|
Add an entry to CHANGELOG.md? |
jnillius
force-pushed
the
fix/periodic-metric-reader-destructor
branch
from
April 17, 2026 06:22
6ddc6de to
c4dc458
Compare
jnillius
force-pushed
the
fix/periodic-metric-reader-destructor
branch
from
April 17, 2026 08:02
c4dc458 to
6948bb0
Compare
marcalff
reviewed
Apr 17, 2026
marcalff
left a comment
Member
There was a problem hiding this comment.
Please fix clang-format.
LGTM otherwise.
- Delete copy/move constructors and assignment operators to satisfy cppcoreguidelines-special-member-functions (Rule of Five). - Remove redundant worker_thread_.join() from destructor; Shutdown() already calls OnShutDown() which joins the thread. - Use std::make_unique in DestroyWithoutShutdown test.
jnillius
force-pushed
the
fix/periodic-metric-reader-destructor
branch
from
April 17, 2026 13:44
6948bb0 to
00cfffb
Compare
marcalff
approved these changes
Apr 17, 2026
marcalff
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks for the contribution.
ThomsonTan
reviewed
Apr 18, 2026
ThomsonTan
approved these changes
Apr 20, 2026
Merged
3 tasks
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4007
Changes
Destroying a PeriodicExportingMetricReader without calling Shutdown()
leaves the background worker thread running inside cv_.wait_for() while
the mutex and condition variable members are destroyed. This causes a
use-after-destroy race detected by ThreadSanitizer.
Add an explicit destructor that calls Shutdown() and joins the worker
thread before member destruction, matching the pattern already used by
BatchSpanProcessor and BatchLogRecordProcessor.
Add a DestroyWithoutShutdown test to verify safe destruction without
an explicit Shutdown() call.
CHANGELOG.mdupdated for non-trivial changes