Skip to content

Commit

Permalink
fix control delete error
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed Jan 26, 2019
1 parent 385c4d3 commit 70ac7d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions server/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 70ac7d3

Please sign in to comment.