From 7e60a1cf39f0f868008247afee79831c0cff60f7 Mon Sep 17 00:00:00 2001 From: yangduo Date: Mon, 22 Jul 2024 20:38:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gamesapi/middleware/caauth.go | 13 +++++++++---- server/gamesapi/middleware/calock.go | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/gamesapi/middleware/caauth.go b/server/gamesapi/middleware/caauth.go index 21e5f156..2e45647a 100644 --- a/server/gamesapi/middleware/caauth.go +++ b/server/gamesapi/middleware/caauth.go @@ -34,7 +34,9 @@ func CaCheck(c *gin.Context) { return } - defer unlockAccount(accountId) + emptyreq := false + + defer unlockAccount(accountId, emptyreq) cache, exist := requestCache.Load(accountId) if !exist { @@ -51,10 +53,10 @@ func CaCheck(c *gin.Context) { if len(*cache) < int(mt.Table.Config.GetMaxCache()) { *cache = append(*cache, info) requestCache.Store(accountId, *cache) - unlockAccount(accountId) + unlockAccount(accountId, emptyreq) for { - time.Sleep(time.Millisecond * 500) + time.Sleep(time.Millisecond * 100) if lockAccount(accountId) { reqlist, _ := requestCache.Load(accountId) @@ -63,7 +65,9 @@ func CaCheck(c *gin.Context) { (*reqlist) = (*reqlist)[1:] if req.sigtime+int64(mt.Table.Config.GetById(0).GetRequestOverTime()) > f5.GetApp().GetRealSeconds() { + redirectRequest.Store(accountId, req) CaForward(req.ori_req, req.sig, req.trace_id) + redirectRequest.Delete(accountId) } else { req.ori_req.JSON(http.StatusOK, gin.H{ "errcode": 1004, @@ -75,12 +79,13 @@ func CaCheck(c *gin.Context) { requestCache.Store(accountId, *reqlist) } else { requestCache.Delete(accountId) + emptyreq = true } return } - unlockAccount(accountId) + unlockAccount(accountId, emptyreq) } } } else { diff --git a/server/gamesapi/middleware/calock.go b/server/gamesapi/middleware/calock.go index 1713560c..908cd48a 100644 --- a/server/gamesapi/middleware/calock.go +++ b/server/gamesapi/middleware/calock.go @@ -16,9 +16,12 @@ func lockAccount(account string) bool { return (*mutex).TryLock() } -func unlockAccount(account string) { +func unlockAccount(account string, del bool) { mutex, exist := accountMutexmap.Load(account) if exist { (*mutex).Unlock() + if del { + accountMutexmap.Delete(account) + } } }