Brighter icon indicating copy to clipboard operation
Brighter copied to clipboard

[Feature] Only support `async` methods in `IDistributedLock`

Open dhickie opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe. When implementing a DynamoDb implementation of IDistributedLock, I came across the issue that the .NET SDK for Dynamo DB doesn't support synchronous methods. As a result, when implementing ObtainLock, there's a risk of deadlock when doing the following:

public bool ObtainLock(string resource)
{
    return ObtainLockAsync(resource, CancellationToken.None).GetAwaiter().GetResult();
}

Describe the solution you'd like Drop the synchronous methods from the interface. Implementations that don't have async methods can use Task.FromResult as a workaround. This would, however, also mean that the lambda passed to the Timer instance in TimedOutboxSweeper would also need to be async.

Additional context Builds on the recent distributed lock work by @preardon.

dhickie avatar May 22 '24 11:05 dhickie

@preardon Can you take a look at this?

iancooper avatar May 22 '24 11:05 iancooper

@iancooper I'm happy to drop sync flows if you are. let me know and I'll get on it

preardon avatar Jun 29 '24 16:06 preardon

Do it

iancooper avatar Jun 30 '24 00:06 iancooper

This has now been merged in for both v9 and v10 and will come out with the next release

#3202 #3203

preardon avatar Jul 12 '24 16:07 preardon