提交 85c4c37e 编写于 作者: M Manish Vasani

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
上级 20dc7403
......@@ -88,7 +88,10 @@ private bool EnqueueCore(TElement value)
waiter = _waiters.Dequeue();
}
waiter.SetResult(value);
// Invoke SetResult on a separate task, as this invocation could cause the underlying task to executing,
// which could be a long running operation that can potentially cause a deadlock if executed on the current thread.
Task.Run(() => waiter.SetResult(value));
return true;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册