fix control delete error

This commit is contained in:
fatedier 2019-01-26 21:36:24 +08:00
parent 385c4d3dd5
commit 70ac7d3d11
2 changed files with 6 additions and 3 deletions

View File

@ -62,11 +62,14 @@ 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()
if c, ok := cm.ctlsByRunId[runId]; ok && c == ctl {
delete(cm.ctlsByRunId, runId)
}
}
func (cm *ControlManager) GetById(runId string) (ctl *Control, ok bool) {
cm.mu.RLock()

View File

@ -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
}