Skip to content

Commit e8150fa

Browse files
committed
Always toggle the retry semaphore on Dispose()
1 parent da087c2 commit e8150fa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

AsyncLock/AsyncLock.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,12 @@ public void Dispose()
312312
// only when the lock is fully unlocked.
313313
@this._parent._owningId = UnlockedId;
314314
@this._parent._owningThreadId = (int)UnlockedId;
315-
if (@this._parent._retry.CurrentCount == 0)
316-
{
317-
@this._parent._retry.Release();
318-
}
315+
}
316+
// We can't place this within the _reentrances == 0 block above because we might
317+
// still need to notify a parallel reentrant task to wake. I think.
318+
if (@this._parent._retry.CurrentCount == 0)
319+
{
320+
@this._parent._retry.Release();
319321
}
320322
}
321323
finally
@@ -401,7 +403,7 @@ public Task<bool> TryLockAsync(Func<Task> callback, TimeSpan timeout)
401403
}).Unwrap();
402404
}
403405

404-
// Make sure InnerLock.LockAsync() does not use await, because an async function triggers a snapshot of
406+
// Make sure InnerLock.TryLockAsync() does not use await, because an async function triggers a snapshot of
405407
// the AsyncLocal value.
406408
public Task<bool> TryLockAsync(Action callback, CancellationToken cancel)
407409
{

0 commit comments

Comments
 (0)