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

Fix deadlock in TestUtilities.TestEventListener #101493

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented Apr 24, 2024

I hit this surprisingly often and mistook it for test hang. From a dotnet dump

First callstack
                   1 System.Threading.Monitor.Enter(Object, Boolean ByRef)             // waits for TestEventListener (instance)
                   1 TestUtilities.TestEventListener.OnEventSourceCreated(EventSource)
                   1 System.Diagnostics.Tracing.EventSource.AddListener(EventListener) // holds EventListener.EventListenersLock
                   1 System.Diagnostics.Tracing.EventListener.AddEventSource(EventSource)
                   1 System.Diagnostics.Tracing.EventSource.Initialize(Guid, String, String[])
                   1 System.Diagnostics.Tracing.EventSource..ctor(EventSourceSettings, String[])
                   1 System.Diagnostics.Tracing.EventSource..ctor(EventSourceSettings)
                   1 System.Diagnostics.Tracing.EventSource..ctor()
                   1 System.Net.NameResolutionTelemetry..ctor()
                   1 System.Net.NameResolutionTelemetry..cctor()
                   1 System.Net.Dns.RunAsync(Func<Object,Int64,__Canon>, Object, CancellationToken)

second callstack
                   1 System.Threading.Monitor.Enter(Object, Boolean ByRef)             // wait for EventListener.EventListenersLock
                   1 System.Diagnostics.Tracing.EventSource.SendCommand(EventListener, EventProviderType, Int32, EventCommand, Boolean, EventLevel, EventKeywords, IDictionary<String,String>)
                   1 System.Diagnostics.Tracing.EventListener.EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>)
                   1 System.Diagnostics.Tracing.EventListener.EnableEvents(EventSource, EventLevel, EventKeywords)
                   1 System.Diagnostics.Tracing.EventListener.EnableEvents(EventSource, EventLevel)
                   1 TestUtilities.TestEventListener.OnEventSourceCreated(EventSource)
                   1 TestUtilities.TestEventListener..ctor(Action<String>, String[])   // holds TestEventListener (instance)
                   1 TestUtilities.TestEventListener..ctor(ITestOutputHelper, String[])

Simply not holding the lock (this) for so long should be enough.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 24, 2024
@rzikm rzikm requested a review from a team April 24, 2024 12:36
@rzikm rzikm added area-System.Net and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 24, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

{
EnableEvents(eventSource, EventLevel.LogAlways);
}
// Second pass called after our ctor, allow logging for specified source names.
Copy link
Member

@CarnaViire CarnaViire Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do a second pass now, do we? You've removed the OnEventSourceCreated call...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see from the callstack above, scratch that

Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

@stephentoub stephentoub merged commit 56ee7c5 into dotnet:main Apr 24, 2024
23 checks passed
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
@karelz karelz added this to the 9.0.0 milestone May 14, 2024
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2024
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.

5 participants