修改
This commit is contained in:
parent
adb0e372ea
commit
7e60a1cf39
@ -34,7 +34,9 @@ func CaCheck(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer unlockAccount(accountId)
|
emptyreq := false
|
||||||
|
|
||||||
|
defer unlockAccount(accountId, emptyreq)
|
||||||
|
|
||||||
cache, exist := requestCache.Load(accountId)
|
cache, exist := requestCache.Load(accountId)
|
||||||
if !exist {
|
if !exist {
|
||||||
@ -51,10 +53,10 @@ func CaCheck(c *gin.Context) {
|
|||||||
if len(*cache) < int(mt.Table.Config.GetMaxCache()) {
|
if len(*cache) < int(mt.Table.Config.GetMaxCache()) {
|
||||||
*cache = append(*cache, info)
|
*cache = append(*cache, info)
|
||||||
requestCache.Store(accountId, *cache)
|
requestCache.Store(accountId, *cache)
|
||||||
unlockAccount(accountId)
|
unlockAccount(accountId, emptyreq)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 100)
|
||||||
|
|
||||||
if lockAccount(accountId) {
|
if lockAccount(accountId) {
|
||||||
reqlist, _ := requestCache.Load(accountId)
|
reqlist, _ := requestCache.Load(accountId)
|
||||||
@ -63,7 +65,9 @@ func CaCheck(c *gin.Context) {
|
|||||||
(*reqlist) = (*reqlist)[1:]
|
(*reqlist) = (*reqlist)[1:]
|
||||||
|
|
||||||
if req.sigtime+int64(mt.Table.Config.GetById(0).GetRequestOverTime()) > f5.GetApp().GetRealSeconds() {
|
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)
|
CaForward(req.ori_req, req.sig, req.trace_id)
|
||||||
|
redirectRequest.Delete(accountId)
|
||||||
} else {
|
} else {
|
||||||
req.ori_req.JSON(http.StatusOK, gin.H{
|
req.ori_req.JSON(http.StatusOK, gin.H{
|
||||||
"errcode": 1004,
|
"errcode": 1004,
|
||||||
@ -75,12 +79,13 @@ func CaCheck(c *gin.Context) {
|
|||||||
requestCache.Store(accountId, *reqlist)
|
requestCache.Store(accountId, *reqlist)
|
||||||
} else {
|
} else {
|
||||||
requestCache.Delete(accountId)
|
requestCache.Delete(accountId)
|
||||||
|
emptyreq = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
unlockAccount(accountId)
|
unlockAccount(accountId, emptyreq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,9 +16,12 @@ func lockAccount(account string) bool {
|
|||||||
return (*mutex).TryLock()
|
return (*mutex).TryLock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func unlockAccount(account string) {
|
func unlockAccount(account string, del bool) {
|
||||||
mutex, exist := accountMutexmap.Load(account)
|
mutex, exist := accountMutexmap.Load(account)
|
||||||
if exist {
|
if exist {
|
||||||
(*mutex).Unlock()
|
(*mutex).Unlock()
|
||||||
|
if del {
|
||||||
|
accountMutexmap.Delete(account)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user