From 80e69cd7d7b7f60fd6db9b8b7989226c3fc07793 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Tue, 4 Mar 2025 11:05:17 +0800 Subject: [PATCH] fix: deadlock in chat --- pkg/common/imapi/caller.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/common/imapi/caller.go b/pkg/common/imapi/caller.go index 3ebee9213..1e091ec1a 100644 --- a/pkg/common/imapi/caller.go +++ b/pkg/common/imapi/caller.go @@ -2,10 +2,11 @@ package imapi import ( "context" - "github.com/openimsdk/tools/log" "sync" "time" + "github.com/openimsdk/tools/log" + "github.com/openimsdk/chat/pkg/eerrs" "github.com/openimsdk/protocol/auth" "github.com/openimsdk/protocol/constant" @@ -75,6 +76,7 @@ func (c *Caller) GetAdminTokenCache(ctx context.Context, userID string) (string, c.lock.RUnlock() if !ok || t.timeout.Before(time.Now()) { c.lock.Lock() + defer c.lock.Unlock() t, ok = c.tokenCache[userID] if !ok || t.timeout.Before(time.Now()) { token, err := c.getAdminTokenServer(ctx, userID) @@ -86,7 +88,6 @@ func (c *Caller) GetAdminTokenCache(ctx context.Context, userID string) (string, t = &authToken{token: token, timeout: time.Now().Add(time.Minute * 5)} c.tokenCache[userID] = t } - c.lock.Unlock() } return t.token, nil }