Files
Nick Khyl 1a4f4eb6ce net/netmon: don't hold mu while closing the OS monitor
On Windows, winMon.Close unregisters the route/address/interface change
callbacks and waits for in-flight ones to return. Those callbacks call
Monitor.isActive, which takes m.mu. Monitor.Close held m.mu across
om.Close, so a change notification arriving during Close deadlocked
with it, and the test binary hung until the timeout.

Release m.mu before calling om.Close. m.closed is already set under the
lock, so late callbacks see the monitor as inactive and return.

This is also the root cause of the Windows "ipnlocal: watchdog timeout"
panics that kill the ipn/ipnlocal and wgengine/netstack test binaries.

Add TestMonitorCloseWaitsForOSCallback, which uses a fake osMon whose
Close, like winipcfg's Unregister, waits for a callback that needs
m.mu. That reproduces the deadlock on any OS.

flakestress TestMonitorCloseWaitsForOSCallback, -p 4, linux:
  before: 16/16 runs deadlocked
  after:  0/135569 runs

Fixes #22228
Fixes #22548

Change-Id: Ibe7740ca23a1ab375d37c280838942f49b4a6a8f
Signed-off-by: Nick Khyl <[email protected]>
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-21 16:16:23 -08:00
..