Skip to content

Commit 369552f

Browse files
authored
Merge pull request #645 from openimsdk/cherry-pick-3197898
fix: deadlock in chat [Created by @icey-yu from #639]
2 parents f4ac62e + 2583ac6 commit 369552f

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

pkg/common/imapi/caller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package imapi
22

33
import (
44
"context"
5-
"github.com/openimsdk/tools/log"
65
"sync"
76
"time"
87

8+
"github.com/openimsdk/tools/log"
9+
910
"github.com/openimsdk/chat/pkg/eerrs"
1011
"github.com/openimsdk/protocol/auth"
1112
"github.com/openimsdk/protocol/constant"
@@ -75,6 +76,7 @@ func (c *Caller) GetAdminTokenCache(ctx context.Context, userID string) (string,
7576
c.lock.RUnlock()
7677
if !ok || t.timeout.Before(time.Now()) {
7778
c.lock.Lock()
79+
defer c.lock.Unlock()
7880
t, ok = c.tokenCache[userID]
7981
if !ok || t.timeout.Before(time.Now()) {
8082
token, err := c.getAdminTokenServer(ctx, userID)
@@ -86,7 +88,6 @@ func (c *Caller) GetAdminTokenCache(ctx context.Context, userID string) (string,
8688
t = &authToken{token: token, timeout: time.Now().Add(time.Minute * 5)}
8789
c.tokenCache[userID] = t
8890
}
89-
c.lock.Unlock()
9091
}
9192
return t.token, nil
9293
}

0 commit comments

Comments
 (0)