From e0e351a04c4f6b8babe2fbc47b49616ee728c92c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 23 Aug 2024 00:34:20 -0300 Subject: [PATCH] Fix deadlock in background translation thread shutdown 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. --- src/ARMeilleure/Translation/TranslatorQueue.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ARMeilleure/Translation/TranslatorQueue.cs b/src/ARMeilleure/Translation/TranslatorQueue.cs index cee2f9080d..831522bc14 100644 --- a/src/ARMeilleure/Translation/TranslatorQueue.cs +++ b/src/ARMeilleure/Translation/TranslatorQueue.cs @@ -80,7 +80,10 @@ namespace ARMeilleure.Translation return true; } - Monitor.Wait(Sync); + if (!_disposed) + { + Monitor.Wait(Sync); + } } }