Fix a race condition in AsyncQueue.EnqueueCore
Cause: We are seeing intermittent deadlocks during build on linux machines running our test suites. The deadlock happens when one thread invokes AtomicSetFlagAndRaiseSymbolDeclaredEvent, and succeeds in setting the flag and invokes SymbolDeclaredEvent while holding onto the lock. The task scheduler decides to inline the event processing, which attempts to execute analyzers while holding onto the _diagnosticLock. Another thread meanwhile is already executing analyzers and calls back into the compiler and is waiting on _diagnosticLock. Fix: Fix the AsyncQueue.EnqueueCore method to invoke SetResult on the waiter task completion source on a separate task. This ensures that no external code executes while attempting to Enqueue a compilation event, and hence cannot deadlock. Testing: All tests pass locally. Fixes #https://github.com/dotnet/roslyn/issues/6098
Showing
想要评论请 注册 或 登录