Commit 7506223
authored
fix: prevent race conditions in SettingsManager setCwd and debounce (#485)
## Summary
- **Concurrent `setCwd()` calls** could produce duplicate file watchers
because both calls cleared `initialized` before either completed
`initialize()`. Added an `initPromise` guard so concurrent calls await
the same initialization.
- **Debounce timer callback** could fire after `dispose()`, reloading
stale settings and calling `onChange` on a disposed manager. Added a
`disposed` flag checked in the async callback before proceeding.
Follows up on #454 which fixed the missing `dispose()` calls — this PR
hardens the `SettingsManager` lifecycle against race conditions.
## Test plan
- [x] `npm run lint` passes
- [x] All settings tests pass
- [x] Verified `disposed` flag prevents stale callback execution
- [x] Verified `initPromise` deduplicates concurrent `initialize()`
calls1 parent ae6c388 commit 7506223
1 file changed
Lines changed: 24 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
95 | 96 | | |
| 97 | + | |
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
| |||
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
110 | 115 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
114 | 125 | | |
115 | 126 | | |
116 | 127 | | |
| |||
235 | 246 | | |
236 | 247 | | |
237 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
238 | 252 | | |
239 | 253 | | |
240 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
241 | 257 | | |
242 | 258 | | |
243 | 259 | | |
| |||
268 | 284 | | |
269 | 285 | | |
270 | 286 | | |
271 | | - | |
272 | 287 | | |
273 | 288 | | |
274 | 289 | | |
275 | 290 | | |
276 | 291 | | |
277 | 292 | | |
278 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
279 | 298 | | |
280 | 299 | | |
281 | 300 | | |
| |||
285 | 304 | | |
286 | 305 | | |
287 | 306 | | |
288 | | - | |
289 | 307 | | |
290 | 308 | | |
0 commit comments