From fe23506471e8a7a94b0615ad5178be99a7e60c90 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 9 Apr 2021 11:13:42 -0700 Subject: [PATCH] ipn/ipnlocal: avoid unneeded initPeerAPIListener work if no changes Signed-off-by: Brad Fitzpatrick --- ipn/ipnlocal/local.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index c6031209a..fc3396132 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -1600,6 +1600,20 @@ func (b *LocalBackend) initPeerAPIListener() { b.mu.Lock() defer b.mu.Unlock() + if len(b.netMap.Addresses) == len(b.peerAPIListeners) { + allSame := true + for i, pln := range b.peerAPIListeners { + if pln.ip != b.netMap.Addresses[i].IP { + allSame = false + break + } + } + if allSame { + // Nothing to do. + return + } + } + b.peerAPIServer = nil for _, pln := range b.peerAPIListeners { pln.Close()