修复 frpc restartProcess 发布未初始化 exec.Cmd 的数据竞争:proc.Cmd/Status 改为 Start 成功后加锁发布

Result: {"status":"keep","total_issues":8,"eslint_errors":0,"eslint_problems":0,"eslint_warnings":0,"golint_canonicalheader":0,"golint_errname":0,"golint_errorlint":1,"golint_exhaustive":0,"golint_forcetypeassert":0,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":0,"golint_recvcheck":1,"golint_test_testifylint":0,"golint_test_thelper":0,"golint_test_total":0,"golint_test_usetesting":0,"golint_total":8,"golint_usestdlibvars":0,"golint_vetx_total":0,"golint_wastedassign":0,"measure_s":75,"tsc_errors":0,"vitest_failed":0,"vitest_total":126}
This commit is contained in:
ryan
2026-08-26 11:19:18 +08:00
parent 55db1c01ec
commit 40232d86ba
3 changed files with 17 additions and 5 deletions
+6 -5
View File
@@ -210,14 +210,15 @@ func (m *Manager) restartProcess(ctx context.Context, relayID string, configPath
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
m.mu.Lock()
proc.Cmd = cmd
proc.Status = "running"
m.mu.Unlock()
startedAt := time.Now()
err := cmd.Start()
if err == nil {
// Start 成功后才发布句柄:Start 之前 cmd.Process 尚未赋值,
// 提前挂到 proc.Cmd 会让读者(测试/状态接口)与 Start 竞争。
m.mu.Lock()
proc.Cmd = cmd
proc.Status = "running"
m.mu.Unlock()
_ = os.WriteFile(pidPath, fmt.Appendf(nil, "%d", cmd.Process.Pid), frpcConfigFilePerm)
err = cmd.Wait()
}