Fixing synchronization bug in ctl functionality
This commit is contained in:
parent
c827375640
commit
4a3b5379b9
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net"
|
||||
// "fmt"
|
||||
)
|
||||
|
||||
func startctl() {
|
||||
@ -68,21 +69,18 @@ func handleClient(commandClient net.Conn) {
|
||||
responseback.Message = "Ok"
|
||||
case "add":
|
||||
logConn("Manually added instance: " + commandmap.Endpoint)
|
||||
ri_mutex.Lock()
|
||||
_, exists := runninginstances[commandmap.Endpoint]
|
||||
//ri_mutex.Lock()
|
||||
_, exists := GetRunner(commandmap.Endpoint)
|
||||
if exists == true {
|
||||
logConn("Already exists: " + commandmap.Endpoint)
|
||||
responseback.Message = "Exists: " + commandmap.Endpoint
|
||||
} else {
|
||||
responseback.Message = "Adding: " + commandmap.Endpoint
|
||||
o := RunningInstance{}
|
||||
o.recentactivities = newUniqueFifo(10)
|
||||
o.recentactors = newUniqueFifo(10)
|
||||
o.client = BuildClient(commandmap.Endpoint)
|
||||
runninginstances[commandmap.Endpoint] = o
|
||||
ri_mutex.Lock()
|
||||
go StartInstance(commandmap.Endpoint)
|
||||
ri_mutex.Unlock()
|
||||
}
|
||||
ri_mutex.Unlock()
|
||||
//ri_mutex.Unlock()
|
||||
case "suspend":
|
||||
logFatal.Fatal("Suspend")
|
||||
case "resume":
|
||||
@ -94,7 +92,9 @@ func handleClient(commandClient net.Conn) {
|
||||
responseback.Type = "status"
|
||||
responseback.RunningInstances = runninginstances
|
||||
|
||||
ri_mutex.Lock()
|
||||
responsebytes, err := json.Marshal(responseback)
|
||||
ri_mutex.Unlock()
|
||||
if err != nil {
|
||||
logFatal.Fatal(err)
|
||||
}
|
||||
@ -107,7 +107,9 @@ func handleClient(commandClient net.Conn) {
|
||||
logFatal.Fatal("Error on write:", err)
|
||||
}
|
||||
|
||||
ri_mutex.Lock()
|
||||
responsebyte, err := json.Marshal(responseback)
|
||||
ri_mutex.Unlock()
|
||||
if err != nil {
|
||||
logFatal.Fatal("Error response back: ", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user