diff --git a/cli/internal/localdaemon/service.go b/cli/internal/localdaemon/service.go index 435cead21..ca01c20e0 100644 --- a/cli/internal/localdaemon/service.go +++ b/cli/internal/localdaemon/service.go @@ -146,7 +146,14 @@ func checkDirectLaunch(ctx context.Context, home string) error { return nil } _, observation, err := loginservice.FindDaemon(ctx, home) - if err != nil || ClassifyService(observation, Discovery{}) != NoService { + if err != nil { + // A caller that gave up during the check hears that, not a change. + if ctxErr := ctx.Err(); ctxErr != nil { + return ctxErr + } + return &ServicePolicyChanged{} + } + if ClassifyService(observation, Discovery{}) != NoService { return &ServicePolicyChanged{} } return nil diff --git a/cli/internal/localdaemon/startup_test.go b/cli/internal/localdaemon/startup_test.go index 7bf7b930a..78762f0b4 100644 --- a/cli/internal/localdaemon/startup_test.go +++ b/cli/internal/localdaemon/startup_test.go @@ -273,6 +273,19 @@ func TestLaunchStartupCancellationAndDeath(t *testing.T) { t.Fatalf("caller cancellation lost: %v", err) } }) + t.Run("cancellation during the service check", func(t *testing.T) { + for delay := range 6 { + home := startupHelper(t, "stall") + ctx, cancel := context.WithCancel(t.Context()) + timer := time.AfterFunc(time.Duration(delay)*time.Millisecond, cancel) + _, err := Launch(ctx, LocalOptions{HomeDir: home}) + timer.Stop() + cancel() + if !errors.Is(err, context.Canceled) { + t.Fatalf("cancelled after %d ms, got %v", delay, err) + } + } + }) t.Run("death", func(t *testing.T) { home := startupHelper(t, "exit") _, err := Launch(t.Context(), LocalOptions{HomeDir: home})