ipn/ipnlocal: fix nil bus panic

Android was hitting a panic due to the event bus not being set when creating a new local backend. This adds a nil check and fallback if the eventbus has not been initiated.

Updates #cleanup

Signed-off-by: kari-ts <kari@tailscale.com>
This commit is contained in:
kari-ts 2025-06-16 11:16:31 -07:00
parent 866614202c
commit a45bc8aa5a

View File

@ -515,7 +515,16 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
captiveCancel: nil, // so that we start checkCaptivePortalLoop when Running captiveCancel: nil, // so that we start checkCaptivePortalLoop when Running
needsCaptiveDetection: make(chan bool), needsCaptiveDetection: make(chan bool),
} }
nb := newNodeBackend(ctx, b.sys.Bus.Get()) var bus *eventbus.Bus
if b.sys != nil {
bus = b.sys.Bus.Get()
}
if bus == nil {
log.Printf("WARNING: sys.Bus is not set; using fallback bus.")
bus = eventbus.New()
}
nb := newNodeBackend(ctx, bus)
b.currentNodeAtomic.Store(nb) b.currentNodeAtomic.Store(nb)
nb.ready() nb.ready()