Conversation
📝 WalkthroughWalkthroughImproves cancellation token lifecycle management in QuerySessionControl's SetStatus method by properly canceling and disposing the previous status clear token before creating a new one, with the field reset to null to prevent stale references. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs (1)
333-341:⚠️ Potential issue | 🟠 MajorGuard delayed status clear from overwriting newer state and ensure proper resource disposal
Line 340 unconditionally nulls
_statusClearCtswithout verifying this callback belongs to the current CTS instance. IfSetStatus()is called again before the delayed callback executes, the older callback can clear the new status and CTS reference. Additionally, the CTS created at line 333 is never disposed on the natural expiry path—it is only disposed ifSetStatus()is called again, creating a resource leak if the method is not invoked after the delay completes.🔧 Proposed fix
if (autoClear && !string.IsNullOrEmpty(text)) { - _statusClearCts = new CancellationTokenSource(); - var token = _statusClearCts.Token; + var cts = new CancellationTokenSource(); + _statusClearCts = cts; + var token = cts.Token; _ = Task.Delay(3000, token).ContinueWith(_ => { Avalonia.Threading.Dispatcher.UIThread.Post(() => { + if (!ReferenceEquals(_statusClearCts, cts)) + return; + StatusText.Text = ""; - _statusClearCts = null; // ← also clear after natural expiry + cts.Dispose(); + _statusClearCts = null; // ← clear after natural expiry }); }, TaskContinuationOptions.OnlyOnRanToCompletion);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs` around lines 333 - 341, The delayed callback is unconditionally nulling and never disposing the CTS it created, which can clear a newer status and leak resources; fix SetStatus() so you capture the local CTS (e.g., var localCts = _statusClearCts) before awaiting Task.Delay, then in the continuation verify that _statusClearCts == localCts before clearing StatusText.Text and setting _statusClearCts = null, and finally dispose the local CancellationTokenSource (call localCts.Dispose()) on the natural expiry path; ensure you continue to respect cancellation by passing the captured token to Task.Delay and not disposing the CTS while it may still be in use.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs`:
- Around line 333-341: The delayed callback is unconditionally nulling and never
disposing the CTS it created, which can clear a newer status and leak resources;
fix SetStatus() so you capture the local CTS (e.g., var localCts =
_statusClearCts) before awaiting Task.Delay, then in the continuation verify
that _statusClearCts == localCts before clearing StatusText.Text and setting
_statusClearCts = null, and finally dispose the local CancellationTokenSource
(call localCts.Dispose()) on the natural expiry path; ensure you continue to
respect cancellation by passing the captured token to Task.Delay and not
disposing the CTS while it may still be in use.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 08863d33-cb6c-4e2c-9386-55c84ab0eaf7
📒 Files selected for processing (1)
src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs
What does this PR do?
A clear description of the change and why it's being made.
Which component(s) does this affect?
How was this tested?
Checklist
dotnet build -c Debug)dotnet test)Summary by CodeRabbit
Release Notes