Skip to content

Commit 2cab63c

Browse files
wallimikewen
authored andcommitted
fix: 修复authToken全局单例导致token无法共存问题 (merge request !72)
Squash merge branch 'feat/walli_20231102_remote_session' into 'master' fix: 修复authToken全局单例导致token无法共存问题
1 parent 4ddd311 commit 2cab63c

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

sessions/remote/remote.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ func (r *RedisManager) getShardLockKey(session dto.Session) string {
129129
// 如果不能,则清理掉 sessionID,将 session 放入 sessionChan 中
130130
// session 的启动,交给 start 中的 for 循环执行,session 不自己递归进行重连,避免递归深度过深
131131
func (r *RedisManager) newConnect(session dto.Session) {
132-
ctx := context.Background()
132+
ctx, cancel := context.WithCancel(context.Background())
133+
defer cancel()
134+
133135
// 锁 shard,避免针对相同 shard 消费重复了
134136
shardLock := lock.New(r.getShardLockKey(session), uuid.NewString(), r.client)
135137
if err := shardLock.Lock(ctx, shardLockExpireTime); err != nil {

token/authtoken.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,11 @@ type AccessTokenInfo struct {
4242
UpTime time.Time
4343
}
4444

45-
var authTokenInstance *AuthTokenInfo
46-
var once sync.Once
47-
4845
func NewAuthTokenInfo() *AuthTokenInfo {
49-
once.Do(func() {
50-
authTokenInstance = &AuthTokenInfo{
51-
lock: &sync.RWMutex{},
52-
forceUpToken: make(chan interface{}, 10),
53-
}
54-
})
55-
return authTokenInstance
46+
return &AuthTokenInfo{
47+
lock: &sync.RWMutex{},
48+
forceUpToken: make(chan interface{}, 10),
49+
}
5650
}
5751

5852
// ForceUpToken 强制刷新Token

0 commit comments

Comments
 (0)