Browse Source

Fix deadlock in background translation thread shutdown (#7239)

TryDequeue checks for _disposed before taking the lock.  If another
thread calls Dispose before it takes the lock, it won't get woken up by
the PulseAll call, and will deadlock in Monitor.Wait.

Double-checking _disposed with the lock taken should avoid this.
David McFarland 1 năm trước cách đây
mục cha
commit
3c61d560c3
1 tập tin đã thay đổi với 4 bổ sung1 xóa
  1. 4 1
      src/ARMeilleure/Translation/TranslatorQueue.cs

+ 4 - 1
src/ARMeilleure/Translation/TranslatorQueue.cs

@@ -80,7 +80,10 @@ namespace ARMeilleure.Translation
                         return true;
                     }
 
-                    Monitor.Wait(Sync);
+                    if (!_disposed)
+                    {
+                        Monitor.Wait(Sync);
+                    }
                 }
             }