Commit da5cb79
committed
fix(event): own graph guard-condition registrations instead of raw pointers
Moving the guard-condition trigger out of the registry lock was necessary --
the trigger is rmw code that re-enters hiroz -- but it turned a deadlock into
a use-after-free.
`trigger_graph_change` snapshotted `Vec<usize>` of raw pointers, released the
lock, then dereferenced them. The lock was the only thing serialising that
against teardown: `rmw_destroy_node` calls
`unregister_graph_guard_condition` and then immediately
`rmw_destroy_guard_condition`, which frees the handle. Previously `unregister`
blocked until triggering finished, so the free could not land mid-trigger.
Afterwards it could, and the trigger wrote through freed memory. Concurrent
triggers also aliased `&mut GuardConditionImpl`.
Make registrations owned. hiroz gains a `GraphGuardCondition` trait and stores
`Arc<dyn GraphGuardCondition>`; the snapshot clones `Arc`s, so an in-flight
trigger keeps its target alive no matter what teardown does. `unregister` is
by `Arc::ptr_eq` and no longer implies "no trigger is running" -- it does not
need to, because the survivor keeps the object alive.
rmw-zenoh-rs splits `GuardConditionImpl` into a C-side handle and an
`Arc<GuardConditionState>` holding the notifier and an `AtomicBool`. The node
registers a clone of that state and keeps one itself for unregistration.
`triggered` becomes atomic because triggering no longer happens under any
lock. The process-wide `set_guard_condition_trigger` indirection is gone --
each registration now carries its own behaviour -- so
`GraphGuardConditionTrigger` is removed.
Covered by a unit test pinning the ownership contract: the registry keeps the
value alive after the registrant drops its handle, and releases it on
unregister. That property is what makes the destroy-during-trigger race
harmless, and unlike the race itself it is deterministic to assert.1 parent 6008b3f commit da5cb79
4 files changed
Lines changed: 196 additions & 60 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
186 | 205 | | |
187 | 206 | | |
188 | 207 | | |
189 | 208 | | |
190 | 209 | | |
191 | | - | |
192 | | - | |
| 210 | + | |
193 | 211 | | |
194 | 212 | | |
195 | 213 | | |
| |||
204 | 222 | | |
205 | 223 | | |
206 | 224 | | |
207 | | - | |
208 | 225 | | |
209 | 226 | | |
210 | 227 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | 228 | | |
216 | 229 | | |
217 | 230 | | |
| |||
244 | 257 | | |
245 | 258 | | |
246 | 259 | | |
247 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
248 | 266 | | |
249 | | - | |
| 267 | + | |
250 | 268 | | |
251 | 269 | | |
252 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
253 | 279 | | |
254 | | - | |
255 | | - | |
| 280 | + | |
256 | 281 | | |
257 | 282 | | |
258 | 283 | | |
| |||
309 | 334 | | |
310 | 335 | | |
311 | 336 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
321 | 347 | | |
322 | 348 | | |
323 | 349 | | |
| |||
696 | 722 | | |
697 | 723 | | |
698 | 724 | | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
699 | 776 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | 98 | | |
111 | 99 | | |
112 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 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 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
6 | 50 | | |
7 | 51 | | |
8 | 52 | | |
9 | 53 | | |
10 | | - | |
11 | | - | |
| 54 | + | |
12 | 55 | | |
13 | 56 | | |
14 | 57 | | |
15 | 58 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 59 | + | |
20 | 60 | | |
21 | 61 | | |
22 | 62 | | |
23 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
24 | 70 | | |
25 | 71 | | |
26 | 72 | | |
27 | 73 | | |
28 | 74 | | |
29 | | - | |
| 75 | + | |
30 | 76 | | |
31 | 77 | | |
32 | 78 | | |
| |||
52 | 98 | | |
53 | 99 | | |
54 | 100 | | |
55 | | - | |
56 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
57 | 105 | | |
58 | 106 | | |
59 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
| |||
44 | 52 | | |
45 | 53 | | |
46 | 54 | | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| |||
122 | 131 | | |
123 | 132 | | |
124 | 133 | | |
125 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
126 | 146 | | |
127 | 147 | | |
128 | 148 | | |
129 | 149 | | |
130 | | - | |
| 150 | + | |
131 | 151 | | |
132 | 152 | | |
133 | 153 | | |
| |||
175 | 195 | | |
176 | 196 | | |
177 | 197 | | |
178 | | - | |
| 198 | + | |
179 | 199 | | |
180 | 200 | | |
181 | 201 | | |
| |||
188 | 208 | | |
189 | 209 | | |
190 | 210 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
199 | 222 | | |
200 | 223 | | |
201 | 224 | | |
| |||
0 commit comments