mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
- time.Ticker.Reset panics on a non-positive duration; a stored auto-update interval of 0 crashed every start (pre_update.go) and every settings save. Route both tickers through configure.IntervalHours, which falls back to one hour. - The auto-updater indexes a startup snapshot; a subscription deleted while it runs panicked out of range in a goroutine and took the daemon down. UpdateSubscription now refuses an index that no longer exists. - ResolveSubscriptionWithClient applied its 30 s timeout floor to a copy it never used, accepted HTTP error pages as an empty node list, and returned zero nodes without error, so UpdateSubscription replaced the stored list with nothing on a provider 403/5xx. Use the copy, reject status >= 400 and empty results. - PutOutbound wrote an error response and then fell through to the success response, producing two JSON bodies. - TestHttpLatency passed nil entries (servers it could not locate) to addHosts, which dereferenced them; skip them. - ReqCache read the per-request mutex map after releasing the lock that guards writes to it (a fatal concurrent map access under load). - The websocket writer ran one goroutine per message box on a single gorilla connection, which forbids concurrent writes; serialize them.
52 lines
931 B
Go
52 lines
931 B
Go
package reqCache
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/v2rayA/v2rayA/common"
|
|
"sync"
|
|
)
|
|
|
|
type reqGlen struct {
|
|
reqIdMu map[string]*sync.Mutex
|
|
reqMu sync.Mutex
|
|
}
|
|
|
|
func newReqGlen() *reqGlen {
|
|
return &reqGlen{
|
|
reqIdMu: make(map[string]*sync.Mutex),
|
|
reqMu: sync.Mutex{},
|
|
}
|
|
}
|
|
|
|
var (
|
|
glen = newReqGlen()
|
|
)
|
|
|
|
func ReqCache(ctx *gin.Context) {
|
|
reqId := ctx.GetHeader(common.RequestIdHeader)
|
|
if reqId == "" {
|
|
return
|
|
}
|
|
glen.reqMu.Lock()
|
|
if resp := common.RespCache.Get(reqId); resp != nil {
|
|
glen.reqMu.Unlock()
|
|
resp := resp.(common.Resp)
|
|
ctx.AbortWithStatusJSON(resp.Status, resp.Body)
|
|
return
|
|
}
|
|
mu, ok := glen.reqIdMu[reqId]
|
|
if !ok {
|
|
mu = new(sync.Mutex)
|
|
glen.reqIdMu[reqId] = mu
|
|
}
|
|
glen.reqMu.Unlock()
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if resp := common.RespCache.Get(reqId); resp != nil {
|
|
resp := resp.(common.Resp)
|
|
ctx.AbortWithStatusJSON(resp.Status, resp.Body)
|
|
return
|
|
}
|
|
ctx.Next()
|
|
}
|