fix: WQL escaping, atomic lock operations, safe CTS disposal (CQ-007, CQ-008, CQ-015)#374
Conversation
📝 WalkthroughWalkthroughPR ChangesService Reliability Fixes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@SysManager/SysManager/Services/PingMonitorService.cs`:
- Around line 59-64: The current Stop logic disposes and nulls _cts prematurely
when _loop is still running, leaking the CTS on timeout; instead attach a
continuation to the background task (_loop) that disposes and nulls _cts only
after the task completes. Modify the Stop/cleanup code around symbols _loop and
_cts so that if Wait(1500) times out you do NOT drop _cts to null immediately
but call _loop?.ContinueWith(...) (or await/async completion) to perform
_cts?.Dispose() and set _cts = null once the task finishes, ensuring disposal
runs exactly when the background task has completed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 00f15256-bdce-43dd-b47c-b37a7a1706d0
📒 Files selected for processing (4)
CHANGELOG.mdSysManager/SysManager/Services/DiskHealthService.csSysManager/SysManager/Services/OperationLockService.csSysManager/SysManager/Services/PingMonitorService.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Analyze (csharp)
- GitHub Check: Build & unit tests
🔇 Additional comments (4)
CHANGELOG.md (1)
9-19: LGTM!SysManager/SysManager/Services/DiskHealthService.cs (1)
72-72: LGTM!SysManager/SysManager/Services/OperationLockService.cs (2)
49-55: LGTM!
82-84: LGTM!
| // Only dispose CTS if the loop actually completed; otherwise the | ||
| // background task still holds a reference to the token and would | ||
| // throw ObjectDisposedException on next cancellation check. | ||
| if (_loop is { IsCompleted: true }) | ||
| _cts?.Dispose(); | ||
| _cts = null; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify Stop() has no deferred CTS disposal path in the current branch.
sed -n '51,90p' SysManager/SysManager/Services/PingMonitorService.cs
rg -n --type=cs -C2 'ContinueWith|_cts\?\.Dispose\(' SysManager/SysManager/Services/PingMonitorService.csRepository: laurentiu021/SystemManager
Length of output: 1913
Defer CTS disposal until the background task actually completes.
The conditional disposal at line 62 only executes when _loop is already completed. However, if Wait(1500) times out, _loop is still running and the CTS is not disposed—the reference is then lost to null at line 64. This creates a resource leak on repeated Start/Stop cycles.
The background task still holds a reference to the cancellation token, so immediate disposal would cause an ObjectDisposedException on its next cancellation check. Instead, chain the disposal to execute after the loop truly completes:
Proposed fix
- if (_loop is { IsCompleted: true })
- _cts?.Dispose();
+ if (_loop is { IsCompleted: true })
+ {
+ _cts?.Dispose();
+ }
+ else if (_loop != null && _cts != null)
+ {
+ var ctsToDispose = _cts;
+ _ = _loop.ContinueWith(
+ _ => ctsToDispose.Dispose(),
+ CancellationToken.None,
+ TaskContinuationOptions.ExecuteSynchronously,
+ TaskScheduler.Default);
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Only dispose CTS if the loop actually completed; otherwise the | |
| // background task still holds a reference to the token and would | |
| // throw ObjectDisposedException on next cancellation check. | |
| if (_loop is { IsCompleted: true }) | |
| _cts?.Dispose(); | |
| _cts = null; | |
| // Only dispose CTS if the loop actually completed; otherwise the | |
| // background task still holds a reference to the token and would | |
| // throw ObjectDisposedException on next cancellation check. | |
| if (_loop is { IsCompleted: true }) | |
| { | |
| _cts?.Dispose(); | |
| } | |
| else if (_loop != null && _cts != null) | |
| { | |
| var ctsToDispose = _cts; | |
| _ = _loop.ContinueWith( | |
| _ => ctsToDispose.Dispose(), | |
| CancellationToken.None, | |
| TaskContinuationOptions.ExecuteSynchronously, | |
| TaskScheduler.Default); | |
| } | |
| _cts = null; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@SysManager/SysManager/Services/PingMonitorService.cs` around lines 59 - 64,
The current Stop logic disposes and nulls _cts prematurely when _loop is still
running, leaking the CTS on timeout; instead attach a continuation to the
background task (_loop) that disposes and nulls _cts only after the task
completes. Modify the Stop/cleanup code around symbols _loop and _cts so that if
Wait(1500) times out you do NOT drop _cts to null immediately but call
_loop?.ContinueWith(...) (or await/async completion) to perform _cts?.Dispose()
and set _cts = null once the task finishes, ensuring disposal runs exactly when
the background task has completed.
… CQ-008, CQ-015) (#374) Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
Summary
Addresses 3 MEDIUM findings from QA audit.
Changes
CQ-007: DiskHealthService WQL injection (MEDIUM)
CQ-008: OperationLockService redundant lock (MEDIUM)
CQ-015: PingMonitorService CTS race (MEDIUM)
Build
Summary by CodeRabbit