Fix shared ptr circular reference leaks#40480
Open
chemwolf6922 wants to merge 1 commit intomasterfrom
Open
Conversation
Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a thread/lifetime ownership cycle in the Windows-side telemetry loggers that could prevent destruction and lead to leaked threads/resources over long uptimes (as reported in #40470). It removes shared_from_this() captures from the worker thread lambdas so the logger objects can be torn down normally.
Changes:
- Remove
std::enable_shared_from_thisinheritance fromGuestTelemetryLoggerandDmesgCollector. - Change worker thread lambdas to capture
thisinstead of ashared_ptrto self, breaking the circular ownership.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/windows/service/exe/GuestTelemetryLogger.h | Drops enable_shared_from_this inheritance to avoid self-owning patterns. |
| src/windows/service/exe/GuestTelemetryLogger.cpp | Updates worker thread capture from shared_from_this() to this to break the ref cycle. |
| src/windows/common/Dmesg.h | Drops enable_shared_from_this inheritance for the collector. |
| src/windows/common/Dmesg.cpp | Updates dmesg worker thread capture from shared_from_this() to this to break the ref cycle. |
Comments suppressed due to low confidence (1)
src/windows/service/exe/GuestTelemetryLogger.cpp:83
- The worker thread treats shutdown as an exception path:
helpers::ConnectPipethrowsE_ABORTwhen any exit event is signaled (includingm_threadExitfrom the destructor). WithCATCH_LOG()this will be logged as an error even though it’s expected during teardown; consider catching explicitly and suppressing/logging-at-debug whenwil::ResultFromCaughtException() == E_ABORT(similar to DmesgCollector’s handling).
}
}
CATCH_LOG()
});
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.
Summary of the Pull Request
Both loggers have their member thread holding a shared pointer of themselves. This renders the m_exitEvents logic useless. And could lead to resource leaks.
Since the thread's lifespan is always shorter than the logger's, changing the capture from shared_from_this to this will fix the leak.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed