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) + } } }