mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-21 02:21:01 +00:00
fix(xray): guard log-writer race and bound handler gRPC deadlines (#5442)
* perf(xray): compile log/traffic regexps once at package scope GetTraffic recompiled two stats regexps on every traffic tick, and LogWriter.Write recompiled two more on every log line. Hoist all four to package-level vars so they compile once at load instead of per call on hot paths. * fix(xray): guard LogWriter.lastLine against the GetResult reader race Write is driven by the Xray process goroutine while Process.GetResult reads lastLine from the caller's goroutine, so the unsynchronized field is a data race under `go test -race`. Add an RWMutex and route every write through setLastLine; GetResult reads via LastLine(). * fix(xray): bound handler gRPC calls with a deadline AddInbound, DelInbound and the AddUser AlterInbound call used context.Background(), so a hung core connection could block the caller indefinitely (for example while the process restart lock is held). Give them a 10s deadline (handlerRPCTimeout) and a nil-client guard, matching the other handler operations.
This commit is contained in:
@@ -273,10 +273,11 @@ func (p *process) GetResult() string {
|
||||
p.mu.RLock()
|
||||
exitErr := p.exitErr
|
||||
p.mu.RUnlock()
|
||||
if len(p.logWriter.lastLine) == 0 && exitErr != nil {
|
||||
lastLine := p.logWriter.LastLine()
|
||||
if len(lastLine) == 0 && exitErr != nil {
|
||||
return exitErr.Error()
|
||||
}
|
||||
return p.logWriter.lastLine
|
||||
return lastLine
|
||||
}
|
||||
|
||||
// GetVersion returns the version string of the Xray process.
|
||||
|
||||
Reference in New Issue
Block a user