From be83f2071eb757e8f7341a28c63ec3ec528eb8a8 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Wed, 21 Aug 2024 10:26:36 -0500 Subject: [PATCH] fix locker timeout issue. --- .../BotSharp.Core/Infrastructures/DistributedLocker.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/DistributedLocker.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/DistributedLocker.cs index 0a5a7cb8..0c20d983 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/DistributedLocker.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/DistributedLocker.cs @@ -12,7 +12,7 @@ public class DistributedLocker _settings = settings; } - public async Task Lock(string resource, Func action, int timeoutInSeconds = 30) + public async Task Lock(string resource, Func> action, int timeoutInSeconds = 30) { var timeout = TimeSpan.FromSeconds(timeoutInSeconds); @@ -20,14 +20,12 @@ public class DistributedLocker var @lock = new RedisDistributedLock(resource, connection.GetDatabase()); await using (var handle = await @lock.TryAcquireAsync(timeout)) { - if (handle != null) - { - await action(); - } - else + if (handle == null) { Serilog.Log.Logger.Error($"Acquire lock for {resource} failed due to after {timeout}s timeout."); } + + return await action(); } }