diff --git a/cmd/tailscale/main.go b/cmd/tailscale/main.go index 61769a9..1d391fd 100644 --- a/cmd/tailscale/main.go +++ b/cmd/tailscale/main.go @@ -475,11 +475,7 @@ func (a *App) runBackend(ctx context.Context) error { } }() case LogoutEvent: - go func() { - ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - b.backend.Logout(ctx) - }() + go a.logout(ctx) case ConnectEvent: state.Prefs.WantRunning = e.Enable go b.backend.SetPrefs(state.Prefs) @@ -571,7 +567,7 @@ func (a *App) runBackend(ctx context.Context) error { } func (a *App) getBugReportID(ctx context.Context, bugReportChan chan<- string, fallbackLog string) { - ctx, cancel := context.WithDeadline(ctx, time.Now().Add(2*time.Second)) + ctx, cancel := context.WithTimeout(ctx, 2*time.Second) defer cancel() r, err := a.localAPIClient.Call(ctx, "POST", "bugreport", nil) defer r.Body().Close() @@ -591,7 +587,7 @@ func (a *App) getBugReportID(ctx context.Context, bugReportChan chan<- string, f } func (a *App) login(ctx context.Context) { - ctx, cancel := context.WithDeadline(ctx, time.Now().Add(2*time.Second)) + ctx, cancel := context.WithTimeout(ctx, 60*time.Second) defer cancel() r, err := a.localAPIClient.Call(ctx, "POST", "login-interactive", nil) defer r.Body().Close() @@ -602,6 +598,22 @@ func (a *App) login(ctx context.Context) { } } +func (a *App) logout(ctx context.Context) error { + ctx, cancel := context.WithTimeout(ctx, 60*time.Second) + defer cancel() + r, err := a.localAPIClient.Call(ctx, "POST", "logout", nil) + defer r.Body().Close() + + if err != nil { + log.Printf("logout: %s", err) + logoutctx, logoutcancel := context.WithTimeout(ctx, 5*time.Minute) + defer logoutcancel() + a.backend.Logout(logoutctx) + } + + return err +} + func (a *App) processWaitingFiles(b *ipnlocal.LocalBackend) error { files, err := b.WaitingFiles() if err != nil {