Skip to content

Commit

Permalink
fix: still reconn when token is invalid
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon <1432970085@qq.com>
  • Loading branch information
FGadvancer committed Jul 27, 2023
1 parent 7e5c2dc commit f4a4b86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions internal/login/init_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (u *LoginMgr) logoutListener(ctx context.Context) {
for {
select {
case <-u.loginMgrCh:
err := u.logout(ctx)
err := u.logout(ctx, true)
if err != nil {
log.ZError(ctx, "logout error", err)
}
Expand Down Expand Up @@ -355,20 +355,22 @@ func (u *LoginMgr) initResources() {
}

// token error recycle recourse, kicked not recycle
func (u *LoginMgr) logout(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
err := u.longConnMgr.SendReqWaitResp(ctx, &push.DelUserPushTokenReq{UserID: u.info.UserID, PlatformID: u.info.PlatformID}, constant.LogoutMsg, &push.DelUserPushTokenResp{})
if err != nil {
log.ZWarn(ctx, "TriggerCmdLogout server recycle resources failed...", err)
} else {
log.ZDebug(ctx, "TriggerCmdLogout server recycle resources success...")
func (u *LoginMgr) logout(ctx context.Context, isTokenValid bool) error {
if !isTokenValid {
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
err := u.longConnMgr.SendReqWaitResp(ctx, &push.DelUserPushTokenReq{UserID: u.info.UserID, PlatformID: u.info.PlatformID}, constant.LogoutMsg, &push.DelUserPushTokenResp{})
if err != nil {
log.ZWarn(ctx, "TriggerCmdLogout server recycle resources failed...", err)
} else {
log.ZDebug(ctx, "TriggerCmdLogout server recycle resources success...")
}
}
u.Exit()
_ = u.db.Close(u.ctx)
// user object must be rest when user logout
u.initResources()
log.ZDebug(ctx, "TriggerCmdLogout client success...")
log.ZDebug(ctx, "TriggerCmdLogout client success...", "isTokenValid", isTokenValid)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/login/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (u *LoginMgr) Login(ctx context.Context, userID, token string) error {
}

func (u *LoginMgr) Logout(ctx context.Context) error {
return u.logout(ctx)
return u.logout(ctx, false)
}

func (u *LoginMgr) SetAppBackgroundStatus(ctx context.Context, isBackground bool) error {
Expand Down

0 comments on commit f4a4b86

Please sign in to comment.