Commit a40d301
Fix vtable mismatch causing infinite waker loops in optimized builds
Summary:
The `tokio-uds-compat` library provides cross-platform Unix domain socket support, enabling the same async socket code to work on both Unix and Windows systems. On Unix, it directly uses Tokio's native Unix domain sockets. On Windows, it bridges between Tokio and the `async-io` runtime using `uds_windows` to emulate Unix domain socket behavior.
A bug caused by this cross-runtime bridging led to CPU spikes in the Myles Daemon, which uses this library. For a detailed account of the investigation, see [this write-up](https://docs.google.com/document/d/1r0llKLSHyykZps6cvIYgdn5HX7y4NfrG4NrilDCFFAE/edit?usp=sharing).
### **Root Cause**
The issue seems to stem from Rust compiler vtable deduplication optimizations in release builds:
1. **Vtable Deduplication**: In optimized builds, the compiler merges identical vtables to save memory
2. **Cross-Runtime Waker Cloning**: When `waker.clone()` was called across Tokio→async-io boundaries, optimization could return different vtable pointers for the same logical task
3. **Failed Identity Checks**: This caused `waker1.will_wake(&waker2)` to return `false` even for identical tasks, since `will_wake()` compares both data pointers AND vtable pointers
4. **Reactor Loop**: async-io's reactor continuously replaced "different" wakers instead of reusing them, creating an infinite polling loop
This diff adds a helper function to prevent vtable mismatches. By cloning the waker at the async-io runtime boundary, this function ensures consistent waker identity across cross-runtime calls, thereby fixing the infinite loop issue. The cloned waker still wakes the same underlying task, so besides fixing the infinite loop, all other behavior should remain the same.
Reviewed By: mengfei1026
Differential Revision: D84855880
fbshipit-source-id: a8b1f4135c587990ffc488ee6b369bfdc821ba351 parent 7043fee commit a40d301
1 file changed
+67
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
| |||
82 | 91 | | |
83 | 92 | | |
84 | 93 | | |
85 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
86 | 101 | | |
87 | 102 | | |
88 | 103 | | |
89 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
90 | 110 | | |
91 | 111 | | |
92 | 112 | | |
93 | 113 | | |
94 | 114 | | |
95 | 115 | | |
96 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
97 | 122 | | |
98 | 123 | | |
99 | 124 | | |
| |||
130 | 155 | | |
131 | 156 | | |
132 | 157 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
144 | 173 | | |
145 | | - | |
146 | | - | |
147 | | - | |
| 174 | + | |
148 | 175 | | |
149 | 176 | | |
150 | 177 | | |
| |||
164 | 191 | | |
165 | 192 | | |
166 | 193 | | |
167 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
168 | 197 | | |
169 | 198 | | |
170 | 199 | | |
171 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
172 | 203 | | |
173 | 204 | | |
174 | 205 | | |
175 | 206 | | |
176 | 207 | | |
177 | 208 | | |
178 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
179 | 212 | | |
180 | 213 | | |
181 | 214 | | |
| |||
198 | 231 | | |
199 | 232 | | |
200 | 233 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
209 | 244 | | |
210 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
211 | 248 | | |
212 | | - | |
213 | | - | |
214 | | - | |
| 249 | + | |
215 | 250 | | |
216 | 251 | | |
217 | 252 | | |
| |||
0 commit comments