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

the question of Foundatio.Lock.ILockProvider #285

Closed
xulei-Itachi opened this issue Apr 5, 2023 · 3 comments
Closed

the question of Foundatio.Lock.ILockProvider #285

xulei-Itachi opened this issue Apr 5, 2023 · 3 comments
Assignees

Comments

@xulei-Itachi
Copy link

code:
class Program
{

    private static readonly ILockProvider _lockProvider =
        new CacheLockProvider(new InMemoryCacheClient(), new InMemoryMessageBus());

    static async Task Main(string[] args)
    {
        var @lock = await _lockProvider.AcquireAsync("TestLock", TimeSpan.FromSeconds(5));

        _ = Task.Run(async () =>
          {
              while (true)
              {
                  await Task.Delay(TimeSpan.FromSeconds(3));
                  await @lock.RenewAsync(TimeSpan.FromSeconds(5));
              }
          });

        _ = Task.Run(async () =>
        {
            while (true)
            {
                await Task.Delay(TimeSpan.FromSeconds(3));
                Console.WriteLine($"state: {await _lockProvider.IsLockedAsync("TestLock")}");
            }
        });

        await Task.Delay(-1);
    }

}

the result I Expected is :
state: True
state: True
state: True
state: True
........

but actually, the result is :
state: True
state: False
state: False
state: False
......

what's the problem?

@xulei-Itachi
Copy link
Author

I Found a bug in Foundatio.Caching.InMemoryCacheClient --> ReplaceIfEqualAsync
you didn't update the expire time when update the cache value.

@niemyjski
Copy link
Member

Awesome find, any chance you could add this as a test case and submit a pr!

@niemyjski
Copy link
Member

@xulei-Itachi could you please submit a pr for this.

@niemyjski niemyjski self-assigned this Jul 26, 2023
niemyjski added a commit that referenced this issue Jul 26, 2023
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