From 59a88ffbab6132fb92cca1cab8e3bf6639f808da Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Mon, 13 May 2024 11:30:08 -0500 Subject: [PATCH] android: only consider backend ready once LocalBackend.Start() has finished This prevents spurious crashes from a nullpointer when we attempt to call localapi while app.localAPIHandler is still null. Updates #cleanup Signed-off-by: Percy Wegmann --- libtailscale/backend.go | 5 +++-- libtailscale/tailscale.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libtailscale/backend.go b/libtailscale/backend.go index 73602c8..20aa3d1 100644 --- a/libtailscale/backend.go +++ b/libtailscale/backend.go @@ -119,7 +119,7 @@ func (a *App) runBackend(ctx context.Context) error { } configs := make(chan configPair) configErrs := make(chan error) - b, err := newBackend(a.dataDir, a.directFileRoot, a.appCtx, a.store, func(rcfg *router.Config, dcfg *dns.OSConfig) error { + b, err := a.newBackend(a.dataDir, a.directFileRoot, a.appCtx, a.store, func(rcfg *router.Config, dcfg *dns.OSConfig) error { if rcfg == nil { return nil } @@ -254,7 +254,7 @@ func (a *App) runBackend(ctx context.Context) error { } } -func newBackend(dataDir, directFileRoot string, appCtx AppContext, store *stateStore, +func (a *App) newBackend(dataDir, directFileRoot string, appCtx AppContext, store *stateStore, settings settingsFunc) (*backend, error) { sys := new(tsd.System) @@ -344,6 +344,7 @@ func newBackend(dataDir, directFileRoot string, appCtx AppContext, store *stateS log.Printf("Failed to start LocalBackend, panicking: %s", err) panic(err) } + a.ready.Done() }() return b, nil } diff --git a/libtailscale/tailscale.go b/libtailscale/tailscale.go index b18b547..df63aec 100644 --- a/libtailscale/tailscale.go +++ b/libtailscale/tailscale.go @@ -36,7 +36,7 @@ func newApp(dataDir, directFileRoot string, appCtx AppContext) Application { dataDir: dataDir, appCtx: appCtx, } - a.ready.Add(1) + a.ready.Add(2) a.store = newStateStore(a.appCtx) netmon.RegisterInterfaceGetter(a.getInterfaces)