Fixes a race condition in Config Admin shutdown#1043
Merged
tcormackMW merged 4 commits intodevelopmentfrom Oct 9, 2024
Merged
Conversation
added 2 commits
September 30, 2024 17:09
tcormackMW
commented
Oct 2, 2024
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## development #1043 +/- ##
===============================================
- Coverage 88.42% 88.40% -0.03%
===============================================
Files 252 252
Lines 12155 12165 +10
===============================================
+ Hits 10748 10754 +6
- Misses 1407 1411 +4
|
jeffdiclemente
requested changes
Oct 9, 2024
jeffdiclemente
approved these changes
Oct 9, 2024
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.
In the current implementation, the ConfigurationAdminImpl object is being destroyed from a thread posted to the AsyncWorkService. This occurs because the ConfigurationListenerImpl holds the last reference to configAdmin. When ConfigurationListenerImpl completes its task of notifying listeners, it releases its reference, triggering the destruction of configAdminImpl. During its destruction, configAdminImpl waits for all its posted tasks to complete, including the NotifyConfigurationUpdated tasks in the AsyncWorkService (which this thread itself is), leading to a deadlock as these tasks can never complete.
Solution
To resolve this issue, I modified the Activator::Stop method for ConfigAdminImpl. Instead of setting configAdminImpl to nullptr immediately after unregistering, ensure that configAdminImpl stops posting new asynchronous work and waits for all existing tasks to complete. This ensures that ConfigurationListenerImpl does not hold the last reference to configAdmin, preventing its premature destruction and avoiding the deadlock
Test Case:
Before change: deadlocks roughly every 1/300 runs
After change: didn't deadlock after 120,000 runs