From 085b54bc888a4b4168e31fe75c4c585bfd3013d0 Mon Sep 17 00:00:00 2001 From: "Abdulazez A." Date: Mon, 11 May 2026 22:49:18 +0300 Subject: [PATCH] proxy: fix data race in /running endpoint and typo in error message (#748) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem The `/running` endpoint in `listRunningProcessesHandler` reads `process.state` directly without holding `stateMutex`. Meanwhile, `swapState()` writes to `process.state` while holding the write lock. This is a data race flagged by the Go race detector. Also fixes a minor typo: "processes was in state" → "process was in state". ## Fix - `proxymanager.go`: Replace `process.state` with `process.CurrentState()` which acquires `stateMutex.RLock()` before reading. - `process.go`: Fix typo in error message. ## Verification - `gofmt -l` — clean - `go test -run "TestProcessGroup_|TestProxyManager_" ./proxy/` — all pass - `go test ./proxy/config/... ./proxy/cache/... ./proxy/configwatcher/...` — all pass --- proxy/process.go | 2 +- proxy/proxymanager.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/proxy/process.go b/proxy/process.go index b679fc93..5c922903 100644 --- a/proxy/process.go +++ b/proxy/process.go @@ -304,7 +304,7 @@ func (p *Process) start() error { return fmt.Errorf("process was already starting but wound up in state %v", state) } } else { - return fmt.Errorf("processes was in state %v when start() was called", curState) + return fmt.Errorf("process was in state %v when start() was called", curState) } } else { return fmt.Errorf("failed to set Process state to starting: current state: %v, error: %v", curState, err) diff --git a/proxy/proxymanager.go b/proxy/proxymanager.go index 8293d1a5..0b5b8578 100644 --- a/proxy/proxymanager.go +++ b/proxy/proxymanager.go @@ -1173,7 +1173,7 @@ func (pm *ProxyManager) listRunningProcessesHandler(context *gin.Context) { if process, ok := pm.matrix.GetProcess(modelID); ok { runningProcesses = append(runningProcesses, gin.H{ "model": process.ID, - "state": process.state, + "state": process.CurrentState(), "cmd": process.config.Cmd, "proxy": process.config.Proxy, "ttl": process.config.UnloadAfter, @@ -1188,7 +1188,7 @@ func (pm *ProxyManager) listRunningProcessesHandler(context *gin.Context) { if process.CurrentState() == StateReady { runningProcesses = append(runningProcesses, gin.H{ "model": process.ID, - "state": process.state, + "state": process.CurrentState(), "cmd": process.config.Cmd, "proxy": process.config.Proxy, "ttl": process.config.UnloadAfter,