Commit c31508e
PT Run: cancel previous query on empty pluginQueryPairs + defer CTS dispose on CancelAndWait timeout
Two fixes spotted while doing a follow-up read of the cancellation refactor for
an unrelated review:
1. MainViewModel.cs — previous session was only cancelled when pluginQueryPairs
had at least one entry. A non-empty QueryText whose QueryBuilder.Build() returns
an empty dictionary (e.g. all global plugins disabled, no keyword match) fell
through both cancellation paths and left the in-flight session running. The
pre-refactor code cancelled _updateSource unconditionally before the Count
check; this restores that invariant by hoisting previousSession.Cancel() +
DisposeWhenComplete() out of the Count > 0 block while keeping _currentSession
bound to the just-cancelled session (so late IResultUpdated events continue to
suppress via their captured token rather than falling back to
CancellationToken.None).
2. QuerySession.CancelAndWait — on timeout, the CTS was disposed unconditionally
while the tracked task may still have been running. That violates the
refactor's own "tasks never observe a disposed CTS" invariant: any future
plugin path that touches token WaitHandles (Register, WaitOne) after timeout
would crash with ObjectDisposedException. The fix gates dispose on the
completed flag and, on timeout, defers disposal via ContinueWith with
DenyChildAttach (mirroring DisposeWhenComplete's pattern).
Also softens the QuerySession remarks: the "structural guarantee" only holds for
callers that capture Token into a local. The class can't prevent a future author
from re-reading _currentSession.Token inside a body, which would reintroduce the
original bug.
Added regression test CancelAndWait_DoesNotDisposeCtsWhileTaskStillRuns covering
the new deferred-disposal behavior; all 10 Wox.Test QuerySessionTest cases pass.
---
ADO: https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/55588441/
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 2eb9fab commit c31508e
3 files changed
Lines changed: 74 additions & 6 deletions
File tree
- src/modules/launcher
- PowerLauncher/ViewModel
- Wox.Test
Lines changed: 16 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
803 | 803 | | |
804 | 804 | | |
805 | 805 | | |
| 806 | + | |
806 | 807 | | |
807 | | - | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
812 | 823 | | |
813 | 824 | | |
814 | 825 | | |
| |||
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
| |||
147 | 153 | | |
148 | 154 | | |
149 | 155 | | |
150 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
151 | 174 | | |
152 | 175 | | |
153 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
138 | 172 | | |
139 | 173 | | |
140 | 174 | | |
| |||
0 commit comments