From 2bd56ecf672540907cbf71be8b242a8034b7fc46 Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Wed, 13 May 2026 15:55:59 +0200 Subject: [PATCH] [client/ui] Remove goroutine from ProfileSwitcher.SwitchActive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Down and Up(async=true) are both fast RPCs; no background goroutine is needed. SwitchActive is now fully synchronous — the tray wraps the call in its own goroutine, and Wails handles React calls similarly. --- client/ui/services/profileswitcher.go | 30 ++++++++++++--------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/client/ui/services/profileswitcher.go b/client/ui/services/profileswitcher.go index 12bea0181..12d92101f 100644 --- a/client/ui/services/profileswitcher.go +++ b/client/ui/services/profileswitcher.go @@ -62,25 +62,21 @@ func (s *ProfileSwitcher) SwitchActive(ctx context.Context, p ProfileRef) error return fmt.Errorf("switch profile %q: %w", p.ProfileName, err) } - // Down and Up run in a goroutine so the caller returns immediately after - // the Switch RPC. Up uses async mode so the goroutine itself is short-lived. - go func() { - bgCtx := context.Background() - if needsDown { - if err := s.connection.Down(bgCtx); err != nil { - log.Errorf("profileswitcher: Down: %v", err) - } + if needsDown { + if err := s.connection.Down(ctx); err != nil { + log.Errorf("profileswitcher: Down: %v", err) } - if wasActive { - if err := s.connection.Up(bgCtx, UpParams{ - ProfileName: p.ProfileName, - Username: p.Username, - Async: true, - }); err != nil { - log.Errorf("profileswitcher: Up %s: %v", p.ProfileName, err) - } + } + + if wasActive { + if err := s.connection.Up(ctx, UpParams{ + ProfileName: p.ProfileName, + Username: p.Username, + Async: true, + }); err != nil { + return fmt.Errorf("reconnect %q: %w", p.ProfileName, err) } - }() + } return nil }