Explorar o código

Fixed all racing conditions

Toby Chui hai 9 meses
pai
achega
b265637a35
Modificáronse 1 ficheiros con 7 adicións e 6 borrados
  1. 7 6
      mod/streamproxy/streamproxy.go

+ 7 - 6
mod/streamproxy/streamproxy.go

@@ -213,14 +213,11 @@ func (c *ProxyRelayConfig) Start() error {
 	if c.UseUDP {
 		c.udpStopChan = udpStopChan
 		go func() {
-			if !c.UseTCP {
-				//By default running state shows TCP proxy. If TCP is not in use, UDP is shown instead
-				c.Running = true
-			}
 			err := c.ForwardUDP(c.ListeningAddress, c.ProxyTargetAddr, udpStopChan)
 			if err != nil {
 				if !c.UseTCP {
 					c.Running = false
+					c.parent.SaveConfigToDatabase()
 				}
 				log.Println("[TCP] Error starting stream proxy " + c.Name + "(" + c.UUID + "): " + err.Error())
 			}
@@ -231,17 +228,18 @@ func (c *ProxyRelayConfig) Start() error {
 		c.tcpStopChan = tcpStopChan
 		go func() {
 			//Default to transport mode
-			c.Running = true
 			err := c.Port2host(c.ListeningAddress, c.ProxyTargetAddr, tcpStopChan)
 			if err != nil {
 				c.Running = false
+				c.parent.SaveConfigToDatabase()
 				log.Println("[TCP] Error starting stream proxy " + c.Name + "(" + c.UUID + "): " + err.Error())
 			}
 		}()
 	}
 
 	//Successfully spawned off the proxy routine
-
+	c.Running = true
+	c.parent.SaveConfigToDatabase()
 	return nil
 }
 
@@ -277,4 +275,7 @@ func (c *ProxyRelayConfig) Stop() {
 
 	log.Println("[STREAM PROXY] Stopped Stream Proxy " + c.Name)
 	c.Running = false
+
+	//Update the running status
+	c.parent.SaveConfigToDatabase()
 }