madelson/DistributedLock

Add mechanism for tracking when a lock's underlying connection dies

madelson opened this issue · 0 comments

There is some discussion of this idea here: #5

The most natural way to expose this is through the returned handle:

SqlDistributedLock myLock = ...
using (var handle = await myLock.AcquireAsync())
{
    handle.GetConnectionBrokenToken().Register(() => Console.WriteLine("oh no, the connection died!");
}

This can be implemented using a cancelable WAITFOR under the hood which should hopefully fail if the SPID dies. It will need to be merged with keepalive in cases where we do that.

Potentially this could be a function on all LockHandles, not just SQL. Some would return CancellationToken.None or throw `NotSupportedException, potentially.

However, this would be a breaking API change (right now handles are simply IDisposable), so this should be left for V2.