Commit 7c807df
fix(mdns): hold lock across SetOptions field update + restart
Cursorbot caught a real race I missed: SetOptions was acquiring the
lock, updating fields, releasing the lock, then calling Restart()
which re-acquires the same lock inside start(true). Between the
unlock and the re-lock, a concurrent Stop() (e.g. SIGINT during a
networkStateChanged) could shut the server down and set
m.server = nil, after which the pending Restart() would build a
fresh server — silently undoing the Stop().
Extract startLocked() as the body of start() assuming the caller
already holds m.lock, and have SetOptions hold the lock continuously
across the field update and the restart. Public Start() / Restart()
still go through start() which acquires the lock as before.
Cursor: #1454 (comment)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 846b975 commit 7c807df
1 file changed
Lines changed: 14 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
217 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
218 | 225 | | |
219 | 226 | | |
220 | 227 | | |
| |||
327 | 334 | | |
328 | 335 | | |
329 | 336 | | |
330 | | - | |
331 | | - | |
332 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
333 | 342 | | |
334 | 343 | | |
| 344 | + | |
335 | 345 | | |
336 | 346 | | |
337 | 347 | | |
338 | 348 | | |
339 | 349 | | |
340 | | - | |
341 | | - | |
| 350 | + | |
342 | 351 | | |
0 commit comments