Files
Zakk 6e6a7deed9 fix(controller): reads no longer wait for a mutation, writes wait for their turn
One `updating` flag guarded thirteen handlers, reads included: while a
subscription update or a latency test ran, GET /touch answered
REQUEST_IN_PROGRESS, so refreshing the page during a test failed at
random. A touch is a database read and needs no turn.

The flag becomes a turn that only the state-changing handlers take, and
a handler that finds it taken waits up to five seconds before answering
REQUEST_IN_PROGRESS instead of refusing at once; a client that leaves
while waiting is not answered.
2026-09-20 04:47:30 +10:00

46 lines
1.0 KiB
Go

package controller
import (
"github.com/gin-gonic/gin"
"github.com/v2rayA/v2rayA/common"
"github.com/v2rayA/v2rayA/db/configure"
"github.com/v2rayA/v2rayA/kernel/touch"
"github.com/v2rayA/v2rayA/kernel/v2ray"
"github.com/v2rayA/v2rayA/server/service"
)
func GetTouch(ctx *gin.Context) {
getTouch(ctx)
}
func getTouch(ctx *gin.Context) {
running := v2ray.ProcessManager.ServiceRunning()
networkPaused := v2ray.ProcessManager.NetworkPaused()
t := touch.GenerateTouch()
common.ResponseSuccess(ctx, gin.H{
"running": running,
"networkPaused": networkPaused,
"touch": t,
})
}
func DeleteTouch(ctx *gin.Context) {
release, ok := beginMutation(ctx)
if !ok {
return
}
defer release()
var ws configure.Whiches
err := ctx.ShouldBindJSON(&ws)
if err != nil {
common.ResponseError(ctx, badRequest("touches", "request body must be {\"touches\": [...]} of server or subscription items"))
return
}
err = service.DeleteWhich(ws.Get())
if err != nil {
common.ResponseError(ctx, logError(err))
return
}
getTouch(ctx)
}