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

Race condition during TraceSource Initialization/Refresh #104457

Closed
h3xds1nz opened this issue Jul 5, 2024 · 3 comments · Fixed by #106192
Closed

Race condition during TraceSource Initialization/Refresh #104457

h3xds1nz opened this issue Jul 5, 2024 · 3 comments · Fixed by #106192
Assignees
Labels
area-System.Diagnostics.TraceSource in-pr There is an active PR which will close this issue when it is merged regression-from-last-release
Milestone

Comments

@h3xds1nz
Copy link

h3xds1nz commented Jul 5, 2024

Description

TraceSource is documented to be a thread-safe, however when you call System.Diagnostics.Trace.Refresh() during TraceSource initialization from a different thread, you have a high chance of receiving either InvalidOperationException or NullReferenceException from the OnInitializing method during the enumeration of Listeners.

There seem to be a lack of synchronization on the collection, this seem to have been introduced in #73087

Reproduction Steps

You can find a demo repository on Github - here.

Expected behavior

I can call System.Diagnostics.Trace.Refresh() safely from a different thread during underlying TraceSource initialization without the risk of crashing.

Actual behavior

A high chance of receiving either InvalidOperationException or NullReferenceException from the OnInitializing method during the enumeration of Listeners as the collection might have been modified or initialized from a different thread.

Regression?

Since #73087, previous .NET version (6) didn't suffer from this issue.

Known Workarounds

In case of WPF, wait some time before invoking a Refresh.

Configuration

.NET 8.0.6 x64 Win10

@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 Jul 5, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jul 5, 2024
@vcsjones vcsjones added area-System.Diagnostics.Tracing and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 5, 2024
Copy link
Contributor

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

@tommcdon
Copy link
Member

tommcdon commented Jul 6, 2024

@noahfalk @hoyosjs

@ericstj
Copy link
Member

ericstj commented Jul 17, 2024

@steveharter can you have a look at this?

@dotnet-policy-service dotnet-policy-service bot added in-pr There is an active PR which will close this issue when it is merged labels Aug 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.TraceSource in-pr There is an active PR which will close this issue when it is merged regression-from-last-release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants