Explorar el Código

fix control delete error

fatedier hace 6 años
padre
commit
70ac7d3d11
Se han modificado 2 ficheros con 6 adiciones y 3 borrados
  1. 5 2
      server/control.go
  2. 1 1
      server/service.go

+ 5 - 2
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) {

+ 1 - 1
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
 }