Commit 9f000d8
authored
fix(mobile): close duplicated TUN fd after engine.Stop to prevent fd leak (#18)
StartTun and StartTunBridge dup the TUN fd so Android and tun2socks each
own an independent copy, preventing a SIGSEGV race on disconnect (commit
41c3eef). However, the dup'd fd was never closed by the Go side —
engine.Stop() closes it only on the happy path; if it panics (the
recover() block swallows it) or engine.Start() never completed, the fd
leaks. On Android, repeated connect/disconnect cycles exhaust the fd
table (EMFILE).
Fix: track the dup'd fd in tunOwnedFd (guarded by engineMu); close it
explicitly after engine.Stop() in StopTun and StopTunBridge, and
defensively close any pre-existing tracked fd before re-inserting in
StartTun and StartTunBridge. On the happy path the explicit close is a
harmless double-close (EBADF ignored1 parent 04128af commit 9f000d8
1 file changed
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
256 | 261 | | |
257 | 262 | | |
258 | 263 | | |
259 | | - | |
| 264 | + | |
260 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
261 | 272 | | |
262 | 273 | | |
| 274 | + | |
263 | 275 | | |
264 | 276 | | |
265 | 277 | | |
| |||
282 | 294 | | |
283 | 295 | | |
284 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
285 | 301 | | |
286 | 302 | | |
287 | 303 | | |
| |||
302 | 318 | | |
303 | 319 | | |
304 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
305 | 324 | | |
306 | 325 | | |
| 326 | + | |
307 | 327 | | |
308 | 328 | | |
309 | 329 | | |
| |||
328 | 348 | | |
329 | 349 | | |
330 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
331 | 355 | | |
332 | 356 | | |
333 | 357 | | |
| |||
0 commit comments