Skip to content

Conversation

@yileicn
Copy link
Collaborator

@yileicn yileicn commented Oct 17, 2025

PR Type

Enhancement, Bug fix


Description

  • Upgrade DistributedLock.Redis to v1.1.0 for improved locking

  • Upgrade StackExchange.Redis to v2.7.33 for stability

  • Handle failed lock acquisition with retry delay

  • Capture lock result and add fallback delay logic


Diagram Walkthrough

flowchart LR
  A["CrontabWatcher Loop"] -->|"LockAsync with result"| B["Lock Acquired?"]
  B -->|"Yes"| C["Run Cron Checker"]
  B -->|"No"| D["Delay 1000ms"]
  C --> E["Delay 1000ms"]
  E --> A
  D --> A
Loading

File Walkthrough

Relevant files
Enhancement
CrontabWatcher.cs
Add lock failure handling with retry delay                             

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabWatcher.cs

  • Capture return value from locker.LockAsync() call
  • Add conditional check for failed lock acquisition
  • Implement retry delay when lock fails
  • Prevent busy-waiting on lock contention
+5/-1     
Dependencies
Directory.Packages.props
Update Redis and DistributedLock dependencies                       

Directory.Packages.props

  • Upgrade DistributedLock.Redis from v1.0.3 to v1.1.0
  • Upgrade StackExchange.Redis from v2.7.27 to v2.7.33
  • Improve distributed locking and Redis client stability
+2/-2     

@qodo-merge-pro
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
- [ ] Create ticket/issue <!-- /create_ticket --create_ticket=true -->

</details></td></tr>
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@Oceania2018 Oceania2018 merged commit 630d1a0 into SciSharp:master Oct 17, 2025
3 of 4 checks passed
@qodo-merge-pro
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Optimize distributed lock usage

To reduce lock contention, move the Task.Delay(1000, stoppingToken) out of the
locker.LockAsync action and place it after the lock block, making it an
unconditional delay within the loop.

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabWatcher.cs [34-42]

-var isLocked = await locker.LockAsync(DIST_KEY, async () =>
+await locker.LockAsync(DIST_KEY, async () =>
 {
     await RunCronChecker(scope.ServiceProvider);
-    await Task.Delay(1000, stoppingToken);
 });
-if (isLocked == false)
-{ 
-    await Task.Delay(1000, stoppingToken);
-}
 
+// Delay to pace the loop, regardless of lock acquisition.
+await Task.Delay(1000, stoppingToken);
+
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies that holding a distributed lock during a Task.Delay is inefficient and increases lock contention, proposing a much better pattern that significantly improves performance and robustness.

High
  • More

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants