From ed250c16b98fe3f69f7ed55e51652fb64242c73a Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Wed, 22 May 2019 17:42:08 +0200 Subject: [PATCH] ConcurrentRequestQueue - Fixed deadlock caused by misunderstanding Monitor.Wait with timeout --- .../Targets/Wrappers/ConcurrentRequestQueue.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/NLog/Targets/Wrappers/ConcurrentRequestQueue.cs b/src/NLog/Targets/Wrappers/ConcurrentRequestQueue.cs index 2869f97118..ddce926832 100644 --- a/src/NLog/Targets/Wrappers/ConcurrentRequestQueue.cs +++ b/src/NLog/Targets/Wrappers/ConcurrentRequestQueue.cs @@ -127,21 +127,13 @@ private long WaitForBelowRequestLimit() // If yield did not help, then wait on a lock while (currentCount > RequestLimit) { + InternalLogger.Debug("Blocking because the overflow action is Block..."); if (!lockTaken) - { - InternalLogger.Debug("Blocking because the overflow action is Block..."); Monitor.Enter(_logEventInfoQueue); - lockTaken = true; - InternalLogger.Trace("Entered critical section."); - } else - { - InternalLogger.Debug("Blocking because the overflow action is Block..."); - if (!Monitor.Wait(_logEventInfoQueue, 100)) - lockTaken = false; - else - InternalLogger.Trace("Entered critical section."); - } + Monitor.Wait(_logEventInfoQueue); + lockTaken = true; + InternalLogger.Trace("Entered critical section."); currentCount = Interlocked.Read(ref _count); }