From 074ad64773f98ae7cfe96757a6c8b1e481b00063 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 28 Mar 2024 16:30:55 +0200 Subject: [PATCH] Cancel previous async login when starting new one --- user.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/user.go b/user.go index 5918505..a5ed8f3 100644 --- a/user.go +++ b/user.go @@ -468,7 +468,7 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str errChanPtr := &errChan if !user.googleAsyncPairErrChan.CompareAndSwap(nil, errChanPtr) { close(errChan) - outErr = ErrLoginInProgress + outErr = fmt.Errorf("%w: wait not called", ErrLoginInProgress) return } var callbackDone bool @@ -480,6 +480,10 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str outEmoji = emoji initialWait.Done() } + if cancelPrevLogin := user.cancelLogin; cancelPrevLogin != nil { + user.zlog.Warn().Msg("Another async google login started while previous one was in progress") + cancelPrevLogin() + } var ctx context.Context ctx, user.cancelLogin = context.WithCancel(context.Background()) go func() {