From 11a20f371a7b88c1511eebb4cf5a2b86c61f1622 Mon Sep 17 00:00:00 2001 From: Tom DNetto Date: Tue, 7 Nov 2023 12:19:43 -0800 Subject: [PATCH] ipn/ipnlocal: fix nil control client panic while updating TKA head As part of tailnet-lock netmap processing, the LocalBackend mutex is unlocked so we can potentially make a network call. Its possible (during shutdown or while the control client is being reset) for b.cc to become nil before the lock is picked up again. Fixes: #9554 Signed-off-by: Tom DNetto --- ipn/ipnlocal/local.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 9cfd345f5..550c26a36 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -1120,15 +1120,19 @@ func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st control b.logf("[v1] TKA sync error: %v", err) } b.mu.Lock() - if b.tka != nil { - head, err := b.tka.authority.Head().MarshalText() - if err != nil { - b.logf("[v1] error marshalling tka head: %v", err) + // As we stepped outside of the lock, it's possible for b.cc + // to now be nil. + if b.cc != nil { + if b.tka != nil { + head, err := b.tka.authority.Head().MarshalText() + if err != nil { + b.logf("[v1] error marshalling tka head: %v", err) + } else { + b.cc.SetTKAHead(string(head)) + } } else { - b.cc.SetTKAHead(string(head)) + b.cc.SetTKAHead("") } - } else { - b.cc.SetTKAHead("") } if !envknob.TKASkipSignatureCheck() {