-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set the async local just before execution #54133
Conversation
- Subscribing to DiagnosticListener.AllListeners replays all created DiagnosticListener instances. Because of this, we need to set the async local just before the execution of the entry point so that we only collect the events that are relevant to the call. Right now, it's also firing with the async local set pre-maturely. - Wrote a concurrency test to make sure it's safe to instantiate the factory in parallel.
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue Details
Follow up to #54090
|
@@ -9,7 +9,7 @@ public class Program | |||
{ | |||
public static void Main(string[] args) | |||
{ | |||
Console.ReadLine(); | |||
System.Threading.Thread.Sleep(-1); |
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.
nit: Thread.Sleep(Timeout.Infinite)
@@ -208,6 +204,10 @@ public object CreateHost() | |||
|
|||
try | |||
{ | |||
// Set the async local to the instance of the HostingListener so we can filter events that | |||
// aren't scoped to this execution of the entry point. | |||
_currentListener.Value = this; |
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.
Do you ever have to "unset" this?
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.
We don't have to because it's on another thread.
Merging this, the test failures are unrelated to the change. |
DiagnosticListener.AllListeners
replays all createdDiagnosticListener
instances. Because of this, we need to set the async local just before the execution of the entry point so that we only collect the events that are relevant to the call. Right now, it's also firing with the async local set pre-maturely, which makes this race when there are many concurrent executions happening.Follow up to #54090