Skip to content

Commit

Permalink
Tentative fix for cancellation in AsyncLock
Browse files Browse the repository at this point in the history
Before this a cancelled LockAsync call would still report a successful
lock and return the inner Release disposable which in turn could lead to
SemaphoreFullException as a lock not held was being released.
  • Loading branch information
niik committed Oct 23, 2015
1 parent 2e26fc8 commit ae1c05f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Akavache.Sqlite3/AsyncLock.cs
Expand Up @@ -19,10 +19,13 @@ public Task<IDisposable> LockAsync(CancellationToken ct = default(CancellationTo
{
var wait = m_semaphore.WaitAsync(ct);

return wait.IsCompleted ?
m_releaser :
wait.ContinueWith((_, state) => (IDisposable)state,
m_releaser.Result, CancellationToken.None,
// Happy path. We synchronously acquired the lock.
if (wait.IsCompleted && !wait.IsFaulted)
return m_releaser;

return wait
.ContinueWith((_, state) => (IDisposable)state,
m_releaser.Result, ct,
TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}

Expand Down

0 comments on commit ae1c05f

Please sign in to comment.