Commit c09bfd8
fs: do not crash when using a closed fs event watcher
Before this commit, when the user calls methods on a closed or
errored fs event watcher, they could hit a crash since the
FSEventWrap in C++ land may have already been destroyed with
the internal pointer set to nullptr. This commit makes sure
that the user cannot hit crashes like that, instead the
methods calling on a closed watcher will be noops.
Also explicitly documents that the watchers should not be used
in `close` and `error` event handlers.
PR-URL: #20985
Fixes: #20738
Fixes: #20297
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ron Korving <ron@ronkorving.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Backport-PR-URL: #211721 parent b4b7d36 commit c09bfd8Copy full SHA for c09bfd8
File tree
Expand file treeCollapse file tree
4 files changed
+74
-10
lines changedOpen diff view settings
Filter options
- doc/api
- lib/internal/fs
- test/parallel
Expand file treeCollapse file tree
4 files changed
+74
-10
lines changedOpen diff view settings
Collapse file
+4-2Lines changed: 4 additions & 2 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
325 | 325 | |
326 | 326 | |
327 | 327 | |
328 | | - |
| 328 | + |
| 329 | + |
329 | 330 | |
330 | 331 | |
331 | 332 | |
| ||
334 | 335 | |
335 | 336 | |
336 | 337 | |
337 | | - |
| 338 | + |
| 339 | + |
338 | 340 | |
339 | 341 | |
340 | 342 | |
|
Collapse file
lib/internal/fs/watchers.js
Copy file name to clipboardExpand all lines: lib/internal/fs/watchers.js+17-4Lines changed: 17 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
100 | 100 | |
101 | 101 | |
102 | 102 | |
103 | | - |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
104 | 108 | |
105 | 109 | |
106 | 110 | |
| ||
120 | 124 | |
121 | 125 | |
122 | 126 | |
| 127 | + |
123 | 128 | |
124 | 129 | |
125 | 130 | |
126 | 131 | |
127 | 132 | |
| 133 | + |
| 134 | + |
| 135 | + |
128 | 136 | |
129 | | - |
| 137 | + |
130 | 138 | |
131 | 139 | |
132 | 140 | |
| ||
148 | 156 | |
149 | 157 | |
150 | 158 | |
151 | | - |
| 159 | + |
| 160 | + |
152 | 161 | |
| 162 | + |
| 163 | + |
| 164 | + |
153 | 165 | |
154 | | - |
| 166 | + |
155 | 167 | |
156 | 168 | |
157 | 169 | |
| 170 | + |
158 | 171 | |
159 | 172 | |
160 | 173 | |
|
Collapse file
test/parallel/test-fs-watch-close-when-destroyed.js
Copy file name to clipboard+38Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
Collapse file
test/parallel/test-fs-watch.js
Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch.js+15-4Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | | - |
| 49 | + |
| 50 | + |
50 | 51 | |
51 | 52 | |
52 | 53 | |
53 | 54 | |
54 | 55 | |
55 | 56 | |
56 | 57 | |
57 | | - |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
58 | 63 | |
59 | 64 | |
60 | 65 | |
| ||
66 | 71 | |
67 | 72 | |
68 | 73 | |
69 | | - |
70 | | - |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
71 | 78 | |
| 79 | + |
| 80 | + |
| 81 | + |
72 | 82 | |
| 83 | + |
73 | 84 | |
74 | 85 | |
75 | 86 | |
|
0 commit comments