From 625c413508c031a25e829b1c4d9acb14db4d24fe Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 1 Mar 2021 20:45:30 -0800 Subject: [PATCH] ipn/ipnlocal: fix another regression from link monitoring refactor Prior to e3df29d488f5ce50ee39, the Engine.SetLinkChangeCallback fired immediately, even if there was no change. The ipnlocal code apparently depended on that, and it broke integration tests (which live in another repo). So mimic the old behavior and call the ipnlocal callback immediately at init. Signed-off-by: Brad Fitzpatrick --- ipn/ipnlocal/local.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 3fd31375b..e3a60515a 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -139,14 +139,19 @@ func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, e wge portpoll: portpoll, gotPortPollRes: make(chan struct{}), } - b.unregisterLinkMon = e.GetLinkMonitor().RegisterChangeCallback(b.linkChange) b.statusChanged = sync.NewCond(&b.statusLock) + linkMon := e.GetLinkMonitor() + // Call our linkChange code once with the current state, and + // then also whenever it changes: + b.linkChange(false, linkMon.InterfaceState()) + b.unregisterLinkMon = linkMon.RegisterChangeCallback(b.linkChange) + return b, nil } -// linkChange is called (in a new goroutine) by wgengine when its link monitor -// detects a network change. +// linkChange is our link monitor callback, called whenever the network changes. +// major is whether ifst is different than earlier. func (b *LocalBackend) linkChange(major bool, ifst *interfaces.State) { b.mu.Lock() defer b.mu.Unlock()