Commit 51fb7e3
NodeWatcher - fix scan / add race, minimise recursive watch delay
Summary:
This addresses some inconsistencies and bugs in the `NodeWatcher` (`fs.watch`-based fallback for non-Watchman, non-macOS), so we can improve test strictness ahead of other changes.
## Scan/'add' race
As noted in the deleted test workarounds, there was previously a race when creating a subtree between
1. The scan of a subtree's contents in when processing the 'add' event for a root.
2. The 'add' event fired at or under the root for a new file or directory, if a watch has already been established.
This could result in multiple add events emitted for a given file or directory.
This diff makes some simple changes to ensure that an add event is only emitted for previously-unwatched directories or previously-unregistered files (`_watchdir` and `_register` return booleans).
## Watch initialisation delays
A distinct but related issue occurred when a file was deleted from a new directory - the deletion may be missed if a watch hasn't yet been established on a new directory.
This turned out to be at least in part because we perform the recursive watch by intercepting directory addition events *within* a debounce wrapper (ie, after an explicit delay).
This diff moves the traversal to begin immediately on processing a directory addition.
Reviewed By: jacdebug
Differential Revision: D41713791
fbshipit-source-id: 714870799f3819a07e7cd96a6d8c87328aaa9ca61 parent 528c891 commit 51fb7e3
3 files changed
Lines changed: 80 additions & 79 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | | - | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
55 | | - | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
62 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
63 | 70 | | |
64 | 71 | | |
65 | 72 | | |
| |||
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
| 92 | + | |
| 93 | + | |
85 | 94 | | |
86 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
87 | 102 | | |
88 | 103 | | |
89 | 104 | | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
93 | 108 | | |
94 | | - | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
98 | 112 | | |
99 | | - | |
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
| |||
146 | 159 | | |
147 | 160 | | |
148 | 161 | | |
149 | | - | |
| 162 | + | |
150 | 163 | | |
151 | | - | |
| 164 | + | |
152 | 165 | | |
153 | | - | |
154 | 166 | | |
155 | 167 | | |
156 | 168 | | |
| |||
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
| 176 | + | |
164 | 177 | | |
165 | 178 | | |
166 | 179 | | |
| |||
249 | 262 | | |
250 | 263 | | |
251 | 264 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
270 | 302 | | |
271 | 303 | | |
272 | 304 | | |
| |||
300 | 332 | | |
301 | 333 | | |
302 | 334 | | |
303 | | - | |
304 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
305 | 340 | | |
306 | 341 | | |
307 | 342 | | |
308 | 343 | | |
309 | | - | |
| 344 | + | |
310 | 345 | | |
311 | 346 | | |
312 | 347 | | |
313 | 348 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
342 | 357 | | |
343 | | - | |
344 | | - | |
| 358 | + | |
| 359 | + | |
345 | 360 | | |
346 | 361 | | |
347 | 362 | | |
| |||
366 | 381 | | |
367 | 382 | | |
368 | 383 | | |
369 | | - | |
| 384 | + | |
| 385 | + | |
370 | 386 | | |
371 | 387 | | |
372 | 388 | | |
Lines changed: 3 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| |||
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 281 | + | |
288 | 282 | | |
289 | 283 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | 284 | | |
299 | 285 | | |
300 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| |||
0 commit comments