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

Lock in OnlineClientManager was flagged by Microsoft support as contributing to deadlock in high volume traffic scenarious #6500

Closed
SergeiGorlovetsky opened this issue Jul 26, 2022 · 4 comments · Fixed by #6620
Assignees
Milestone

Comments

@SergeiGorlovetsky
Copy link

Hi,
One of our clients has been experiencing Thread Exhaustion issues and after analysing memory dumps and .net profiler traces the recommendation was:
" As with most performance issues, the scene is complex. However, the most prominent issue is definitely the huge number of blocked threads that are all waiting on the synclock to either call Abp.RealTime.OnlineClientManager.Add or Abp.RealTime.OnlineClientManager.Remove. The application cannot get that lock because another thread has the lock and it’s itself blocked on the lock for another object, a System.Collections.Concurrent.BlockingCollection in Nito.AsyncEx.AsyncContext. Note none of these are Microsoft libraries, what was found matches a known issue talked about here: Deadlock with AsyncReaderWriterLock · Issue #255 · StephenCleary/AsyncEx (github.com) as well as here: Another deadlock - or at least a very slow lock · Issue #107 · StephenCleary/AsyncEx (github.com)
To try and make this accessible: Under load, the application needs to have free threads in order to unlock the lock on the AsyncContext::TaskQueue. If the threadpool is exhausted, then best case the thread will block for 2 seconds until a new thread is added to the pool. Under load, that thread might be assigned to other duties! The other duties though just end up leading to calls to the first locked object (OnlineClientManager) where they block, adding to the thread pool exhaustion.
"
I've noticed a note a TODO note in OnlineClientManager code suggesting to remove SyncObj as the default store is thread safe.
Please advise of your thoughts on this.

Thanks,
Sergei Gorlovetsky

@ismcagdas
Copy link
Member

Hi @SergeiGorlovetsky I think at the time of writing OnlineClientManager, we couldn't be sure about InMemoryOnlineClientStore is thread safe or not but when I look at it, it seems fine. To try this, you can create your own version of OnlineClientManager and use it in your project and test it.

@SergeiGorlovetsky
Copy link
Author

Thank you Ismail, Indeed InMemoryOnlineClientStore uses ConcurrentDictionary and it is thread safe. We are going to remove the lock and load test.

@stale
Copy link

stale bot commented Oct 1, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 1, 2022
@ismcagdas ismcagdas added this to the v8.0 milestone Oct 19, 2022
@ismcagdas ismcagdas self-assigned this Oct 19, 2022
@stale stale bot removed the wontfix label Oct 19, 2022
@ismcagdas
Copy link
Member

@SergeiGorlovetsky did you have a chance to test this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants