Fix for deadlocks brought out by the GroupPresentation test. #2886
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.
This PR focuses on two potential deadlock scenarios, both in the subscriber impl code, the function to get a list of current data readers and a function to notify datareaders. The problem is that multiple threads are passing through these functions and must mediate the sharing of resources using locks. However there is a lock on the SubscriberImpl object that is grabbed a the start of these functions, then during processing a second lock on the DataReaderImpl object is repeatedly taken while evaluating individual data readers. This triggers a deadlock when a thread is holding the DataReaderImpl instance lock and waiting for the SubscriberImpl lock, but another thread is holding the SI lock and wants the particular DataReaderImpl instance lock currently held by the first thread.
This solution is to make a local copy of the data reader collection to be searched then release the SI lock before iterating the data reader collection. This avoids the deadlock condition.