This commit is contained in:
yangduo 2024-07-22 20:38:51 +08:00
parent adb0e372ea
commit 7e60a1cf39
2 changed files with 13 additions and 5 deletions

View File

@ -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 {

View File

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