Skip to content
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

Merged
merged 2 commits into from
Jun 14, 2021
Merged

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Jun 14, 2021

  • 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, which makes this race when there are many concurrent executions happening.
  • Wrote a concurrency test to make sure it's safe to instantiate the factory in parallel.

Follow up to #54090

- 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.
@ghost
Copy link

ghost commented Jun 14, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details
  • 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.

Follow up to #54090

Author: davidfowl
Assignees: -
Labels:

area-Extensions-Hosting

Milestone: -

@davidfowl davidfowl changed the title Set the async local just before execution. Set the async local just before execution Jun 14, 2021
@@ -9,7 +9,7 @@ public class Program
{
public static void Main(string[] args)
{
Console.ReadLine();
System.Threading.Thread.Sleep(-1);
Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

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.

@davidfowl
Copy link
Member Author

Merging this, the test failures are unrelated to the change.

@davidfowl davidfowl merged commit 2ac5e2b into main Jun 14, 2021
@akoeplinger akoeplinger deleted the davidfowl/fix-async-local-set branch June 24, 2021 11:02
@ghost ghost locked as resolved and limited conversation to collaborators Jul 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants