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 a deadlock in EventSource and CounterGroup #40259

Merged
merged 5 commits into from
Aug 15, 2020

Conversation

sywhang
Copy link
Contributor

@sywhang sywhang commented Aug 3, 2020

Fix #40190

A deadlock can occur when the callback encountered in counter.WritePayload() contains a path that contains a EventSource constructor. EventSource constructor tries to take EventSource.EventListenerLock which may already be held by another thread. Simultaneously, the thread that holds to the EventListenerLock can be blocked on s_CounterGroupLock if it calls enable on an EventSource with EventCounter enabled, resulting in a deadlock.

Essentially the only change in this PR is taking out the call to counter.WritePayload(); to out of the scope of s_counterGroupLock. The fields in CounterGroup (both static and non-static) are still read/written inside s_counterGroupLock.

Note: We may need to backport this fix to 3.1.

@sywhang sywhang added this to the 5.0.0 milestone Aug 3, 2020
Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

Still a few issues to work out, comments inline

@sywhang sywhang requested a review from noahfalk August 13, 2020 00:15
Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @sywhang!

@sywhang sywhang merged commit c67684b into dotnet:master Aug 15, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
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.

Using EventCounter/EventListener can run into a deadlock
2 participants