From cdc10b74f132f36842f9d0e8c25dad299e5b14ab Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Fri, 28 Feb 2020 15:12:49 -0500 Subject: [PATCH] ipn: always guard LocalBackend.endpoints with mu For #112 Signed-off-by: David Crawshaw --- ipn/local.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ipn/local.go b/ipn/local.go index 563b43c73..4f83ebb7c 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -48,7 +48,7 @@ type LocalBackend struct { hiCache *tailcfg.Hostinfo netMapCache *controlclient.NetworkMap engineStatus EngineStatus - endPoints []string // TODO: many uses without holding mu + endpoints []string blocked bool authURL string interact int @@ -191,10 +191,11 @@ func (b *LocalBackend) Start(opts Options) error { b.mu.Lock() b.c = cli + endpoints := b.endpoints b.mu.Unlock() - if b.endPoints != nil { - cli.UpdateEndpoints(0, b.endPoints) + if endpoints != nil { + cli.UpdateEndpoints(0, endpoints) } cli.SetStatusFunc(func(newSt controlclient.Status) { @@ -262,16 +263,17 @@ func (b *LocalBackend) Start(opts Options) error { log.Fatalf("weird: non-error wgengine update with status=nil\n") } - b.mu.Lock() // why does this hold b.mu? parseWgStatus only reads b.logf es := b.parseWgStatus(s) + + b.mu.Lock() c := b.c b.engineStatus = es + b.endpoints = append([]string{}, s.LocalAddrs...) b.mu.Unlock() if c != nil { c.UpdateEndpoints(0, s.LocalAddrs) } - b.endPoints = append([]string{}, s.LocalAddrs...) b.stateMachine() b.statusLock.Lock()