[优化] 确保所有管理的进程在停止时被正确取消和清理

This commit is contained in:
ryan
2026-06-02 21:30:48 +08:00
parent f29292dd81
commit dfd040a9de
4 changed files with 70 additions and 1 deletions
+18 -1
View File
@@ -150,7 +150,10 @@ func (m *Manager) restartProcess(ctx context.Context, relayID string, configPath
_ = os.Remove(pidPath)
}
procCtx, cancel := context.WithCancel(context.Background())
if ctx == nil {
ctx = context.Background()
}
procCtx, cancel := context.WithCancel(ctx)
proc := &Process{
RelayID: relayID,
Cancel: cancel,
@@ -223,6 +226,20 @@ func (m *Manager) restartProcess(ctx context.Context, relayID string, configPath
}()
}
func (m *Manager) Stop() {
m.mu.Lock()
defer m.mu.Unlock()
for relayID, proc := range m.processes {
if proc != nil && proc.Cancel != nil {
proc.Cancel()
}
pidPath := filepath.Join(m.cfg.DataDir, fmt.Sprintf("frpc_%s.pid", relayID))
_ = os.Remove(pidPath)
delete(m.processes, relayID)
}
}
func buildFrpcToml(relay service.FlaredRelayInfo, proxies []service.FlaredProxyEntry) string {
var buf bytes.Buffer