wgengine/monitor: fix panic due to race on Windows

It's possible for the 'somethingChanged' callback to be registered and
then trigger before the ctx field is assigned; move the assignment
earlier so this can't happen.

Change-Id: Ia7ee8b937299014a083ab40adf31a8b3e0db4ec5
Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
pull/6724/head
Andrew Dunham 2 years ago
parent d81a2b2ce2
commit 0d47cd2284

@ -51,11 +51,13 @@ func newOSMon(logf logger.Logf, _ *Mon) (osMon, error) {
messagec: make(chan eventMessage, 1),
noDeadlockTicker: time.NewTicker(5000 * time.Hour), // arbitrary
}
m.ctx, m.cancel = context.WithCancel(context.Background())
var err error
m.addressChangeCallback, err = winipcfg.RegisterUnicastAddressChangeCallback(m.unicastAddressChanged)
if err != nil {
m.logf("winipcfg.RegisterUnicastAddressChangeCallback error: %v", err)
m.cancel()
return nil, err
}
@ -63,11 +65,10 @@ func newOSMon(logf logger.Logf, _ *Mon) (osMon, error) {
if err != nil {
m.addressChangeCallback.Unregister()
m.logf("winipcfg.RegisterRouteChangeCallback error: %v", err)
m.cancel()
return nil, err
}
m.ctx, m.cancel = context.WithCancel(context.Background())
return m, nil
}

Loading…
Cancel
Save