diff --git a/cmd/tsconnect/wasm/wasm_js.go b/cmd/tsconnect/wasm/wasm_js.go index baf5d0160..31267a2ef 100644 --- a/cmd/tsconnect/wasm/wasm_js.go +++ b/cmd/tsconnect/wasm/wasm_js.go @@ -329,7 +329,7 @@ func (i *jsIPN) logout() { go func() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - i.lb.LogoutSync(ctx) + i.lb.Logout(ctx) }() } diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 550b15dc0..2d8b953d9 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -566,7 +566,7 @@ func (b *LocalBackend) Shutdown() { ctx, cancel := context.WithTimeout(b.ctx, 5*time.Second) defer cancel() t0 := time.Now() - err := b.LogoutSync(ctx) // best effort + err := b.Logout(ctx) // best effort td := time.Since(t0).Round(time.Millisecond) if err != nil { b.logf("failed to log out ephemeral node on shutdown after %v: %v", td, err) @@ -3907,7 +3907,9 @@ func (b *LocalBackend) ShouldHandleViaIP(ip netip.Addr) bool { return false } -func (b *LocalBackend) LogoutSync(ctx context.Context) error { +// Logout logs out the current profile, if any, and waits for the logout to +// complete. +func (b *LocalBackend) Logout(ctx context.Context) error { b.mu.Lock() if !b.hasNodeKeyLocked() { // Already logged out. diff --git a/ipn/ipnlocal/state_test.go b/ipn/ipnlocal/state_test.go index b79d68d2d..a354bb9a7 100644 --- a/ipn/ipnlocal/state_test.go +++ b/ipn/ipnlocal/state_test.go @@ -580,7 +580,7 @@ func TestStateMachine(t *testing.T) { store.awaitWrite() t.Logf("\n\nLogout") notifies.expect(5) - b.LogoutSync(context.Background()) + b.Logout(context.Background()) { nn := notifies.drain(5) previousCC.assertCalls("pause", "Logout", "unpause", "Shutdown") @@ -610,7 +610,7 @@ func TestStateMachine(t *testing.T) { // A second logout should be a no-op as we are in the NeedsLogin state. t.Logf("\n\nLogout2") notifies.expect(0) - b.LogoutSync(context.Background()) + b.Logout(context.Background()) { notifies.drain(0) cc.assertCalls() @@ -623,7 +623,7 @@ func TestStateMachine(t *testing.T) { // AuthCantContinue state. t.Logf("\n\nLogout3") notifies.expect(3) - b.LogoutSync(context.Background()) + b.Logout(context.Background()) { notifies.drain(0) cc.assertCalls() diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go index dcb2e60cc..3ea796ccd 100644 --- a/ipn/localapi/localapi.go +++ b/ipn/localapi/localapi.go @@ -1056,7 +1056,7 @@ func (h *Handler) serveLogout(w http.ResponseWriter, r *http.Request) { http.Error(w, "want POST", 400) return } - err := h.b.LogoutSync(r.Context()) + err := h.b.Logout(r.Context()) if err == nil { w.WriteHeader(http.StatusNoContent) return