From 021d666657e948310f2549695bf0d00875521dd8 Mon Sep 17 00:00:00 2001 From: VSadov Date: Sat, 21 May 2016 11:45:31 -0700 Subject: [PATCH] Upon completion give waiters up to 10 sec. to report diagnostics before canceling --- .../Portable/DiagnosticAnalyzer/AsyncQueue.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.cs index 547c64498b0..1588cf6b4da 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.cs @@ -177,6 +177,21 @@ private bool CompleteCore() { if (existingWaiters != null) { + // we have waiters and we have data. + // allow some extra time to drain the queue before cancelling + // but do not wait for too long. + SpinWait.SpinUntil(() => + { + lock (SyncObject) + { + return _data.Count == 0; + } + }, + 10000); + + // cancel waiters. + // NOTE: this could result in losing diagnostics + // see https://github.com/dotnet/roslyn/issues/11470 foreach (var tcs in existingWaiters) { tcs.SetCanceled(); -- GitLab