Repository navigation
Commit efc8678
committed
fix(McpHub): pass cancellationDisposable to cleanup() to avoid TDZ on sync cancellation
When CancellationToken.onCancellationRequested() registers a listener
on an already-cancelled token, VS Code fires the callback synchronously
inside the registration call — before the `const cancellationDisposable
= onCancellationRequested(...)` assignment completes. The old `let`-
predeclared shape was no-op-safe via optional chaining, but the
prefer-const consolidation in this PR put `cancellationDisposable`
into the temporal dead zone for the duration of the sync callback,
turning the already-cancelled path into a ReferenceError.
Restructured cleanup() to receive the disposable as a parameter
instead of capturing it from outer scope:
- cleanup signature now takes `disposable?: vscode.Disposable`
- non-callback call sites pass cancellationDisposable explicitly
- the cancellation callback calls cleanup() with no arg; VS Code's
CancellationToken cleans up its own listener after firing, so
disposing from inside the listener was already redundant
Keeps cancellationDisposable as a const, so prefer-const remains
satisfied. Includes a regression test that fires the cancellation
listener synchronously during registration and asserts the flow
resolves cleanly.1 parent 21dd749 commit efc8678
2 files changed
Lines changed: 53 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1130 | 1130 | | |
1131 | 1131 | | |
1132 | 1132 | | |
1133 | | - | |
| 1133 | + | |
1134 | 1134 | | |
1135 | 1135 | | |
1136 | 1136 | | |
1137 | 1137 | | |
1138 | | - | |
| 1138 | + | |
1139 | 1139 | | |
1140 | 1140 | | |
1141 | 1141 | | |
| |||
1146 | 1146 | | |
1147 | 1147 | | |
1148 | 1148 | | |
1149 | | - | |
| 1149 | + | |
1150 | 1150 | | |
1151 | 1151 | | |
1152 | 1152 | | |
| |||
1155 | 1155 | | |
1156 | 1156 | | |
1157 | 1157 | | |
1158 | | - | |
| 1158 | + | |
1159 | 1159 | | |
1160 | 1160 | | |
1161 | 1161 | | |
| |||
1175 | 1175 | | |
1176 | 1176 | | |
1177 | 1177 | | |
1178 | | - | |
| 1178 | + | |
1179 | 1179 | | |
1180 | 1180 | | |
1181 | 1181 | | |
| |||
1189 | 1189 | | |
1190 | 1190 | | |
1191 | 1191 | | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1192 | 1199 | | |
1193 | 1200 | | |
1194 | 1201 | | |
| |||
1206 | 1213 | | |
1207 | 1214 | | |
1208 | 1215 | | |
1209 | | - | |
| 1216 | + | |
1210 | 1217 | | |
1211 | 1218 | | |
1212 | 1219 | | |
| |||
1244 | 1251 | | |
1245 | 1252 | | |
1246 | 1253 | | |
1247 | | - | |
| 1254 | + | |
1248 | 1255 | | |
1249 | 1256 | | |
1250 | 1257 | | |
| |||
1257 | 1264 | | |
1258 | 1265 | | |
1259 | 1266 | | |
1260 | | - | |
| 1267 | + | |
1261 | 1268 | | |
1262 | 1269 | | |
1263 | 1270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2582 | 2582 | | |
2583 | 2583 | | |
2584 | 2584 | | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
2585 | 2623 | | |
2586 | 2624 | | |
2587 | 2625 | | |
| |||
0 commit comments