Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About Distribute Locking System using Redis #169

Open
KandarpPatel07 opened this issue Sep 14, 2023 · 2 comments
Open

About Distribute Locking System using Redis #169

KandarpPatel07 opened this issue Sep 14, 2023 · 2 comments

Comments

@KandarpPatel07
Copy link

Hi
I have one doubt regarding the use of the library in order to implement the feature of a distributed locking system
like there is one scenario
Let's say service-1 occupies a lock on resource-1 and during handling the process it goes in an infinite loop and never returns hence the lock that is acquired is never released is there any mechanism that the key that is set in the redis gets timed out and automatically delete

@madelson
Copy link
Owner

Hi @KandarpPatel07 thanks for your interest in the library. Currently, Redis locks do operate on a timeout but they have "auto-renewal" set up such that the process holding the lock will periodically re-up the timeout if the lock has not been released. Typically, you don't want the process holding the lock to silently lose it just because an operation took longer than expected.

That said, if you want to mandate an absolute timeout for the lock hold, today you can do so like this:

await using (var handle = await myDistributedLock.AcquireAsync())
{
       // force-release the lock after 10 minutes
       Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith(_ => handle.Dispose());

       // potential infinite loop here
}

If there was sufficient interest, potentially this could be built directly into the library as a new option.

@madelson
Copy link
Owner

Related (but different) ask: #130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants