-
Notifications
You must be signed in to change notification settings - Fork 67
Fix race condition in generic diagnostic listener #948
Conversation
Please ignore build failure, it was cancelled, re-started and passed, but github did not pick up successful run |
private List<IDisposable> individualSubscriptions; | ||
|
||
protected DiagnosticSourceListenerBase(TelemetryConfiguration configuration) | ||
{ | ||
this.Configuration = configuration; | ||
this.Client = new TelemetryClient(configuration); | ||
} | ||
|
||
public void Subscribe() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this public method, can you please add a
describing What this is, Why this is?
@@ -16,13 +16,25 @@ internal abstract class DiagnosticSourceListenerBase<TContext> : IObserver<Diagn | |||
protected readonly TelemetryClient Client; | |||
protected readonly TelemetryConfiguration Configuration; | |||
|
|||
private readonly IDisposable listenerSubscription; | |||
private IDisposable listenerSubscription; | |||
private List<IDisposable> individualSubscriptions; | |||
|
|||
protected DiagnosticSourceListenerBase(TelemetryConfiguration configuration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the Subscribe method is required, should we make a reference to it in the constructor?
I don't know how often a developer creates a new DiagnosticSourceListener (probably not often :) ), but I wonder that they may not know to look for the Subscribe method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an internal class, it's only us who call this method and just once. I can add the comment, though
When generic diagnostic listener subscribes to DiagnosticSource, it attempts to use this in its own constructor, while some properties (filters) are not initialized yet.
As a result, if DiagnosticSource is created BEFORE the generic listener, it's guaranteed to miss subscription event and never receive anything.
This PR fixes this issue.
For significant contributions please make sure you have completed the following items:
Changes in public surface reviewed
Design discussion issue #
CHANGELOG.md updated with one line description of the fix, and a link to the original issue.
The PR will trigger build, unit tests, and functional tests automatically. If your PR was submitted from fork - mention one of committers to initiate the build for you.
If you want to to re-run the build/tests, the easiest way is to simply Close and Re-Open this same PR. (Just click 'close pull request' followed by 'open pull request' buttons at the bottom of the PR)
Please follow [these] (https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/develop/CONTRIBUTING.md) instructions to build and test locally.