diff --git a/server/control.go b/server/control.go index 90a35844..169e173f 100644 --- a/server/control.go +++ b/server/control.go @@ -62,10 +62,13 @@ func (cm *ControlManager) Add(runId string, ctl *Control) (oldCtl *Control) { return } -func (cm *ControlManager) Del(runId string) { +// we should make sure if it's the same control to prevent delete a new one +func (cm *ControlManager) Del(runId string, ctl *Control) { cm.mu.Lock() defer cm.mu.Unlock() - delete(cm.ctlsByRunId, runId) + if c, ok := cm.ctlsByRunId[runId]; ok && c == ctl { + delete(cm.ctlsByRunId, runId) + } } func (cm *ControlManager) GetById(runId string) (ctl *Control, ok bool) { diff --git a/server/service.go b/server/service.go index bbeb8b1a..440b6942 100644 --- a/server/service.go +++ b/server/service.go @@ -353,7 +353,7 @@ func (svr *Service) RegisterControl(ctlConn frpNet.Conn, loginMsg *msg.Login) (e go func() { // block until control closed ctl.WaitClosed() - svr.ctlManager.Del(loginMsg.RunId) + svr.ctlManager.Del(loginMsg.RunId, ctl) }() return }