Skip to content

Commit

Permalink
Merge pull request #3415 from snakefoot/NetCoreAsyncQueueDeadlock
Browse files Browse the repository at this point in the history
ConcurrentRequestQueue - Fixed deadlock caused by misunderstanding Monitor.Wait
  • Loading branch information
304NotModified committed May 22, 2019
2 parents df0c1b6 + ed250c1 commit 54b5180
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/NLog/Targets/Wrappers/ConcurrentRequestQueue.cs
Expand Up @@ -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);
}

Expand Down

0 comments on commit 54b5180

Please sign in to comment.