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 <tom@tailscale.com>
pull/10173/head
Tom DNetto 1 year ago committed by Tom
parent 3496d62ed3
commit 11a20f371a

@ -1120,15 +1120,19 @@ func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st control
b.logf("[v1] TKA sync error: %v", err) b.logf("[v1] TKA sync error: %v", err)
} }
b.mu.Lock() b.mu.Lock()
if b.tka != nil { // As we stepped outside of the lock, it's possible for b.cc
head, err := b.tka.authority.Head().MarshalText() // to now be nil.
if err != nil { if b.cc != nil {
b.logf("[v1] error marshalling tka head: %v", err) 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 { } else {
b.cc.SetTKAHead(string(head)) b.cc.SetTKAHead("")
} }
} else {
b.cc.SetTKAHead("")
} }
if !envknob.TKASkipSignatureCheck() { if !envknob.TKASkipSignatureCheck() {

Loading…
Cancel
Save