From 4a3b5379b96862df25cce2dc8ffc08d0ccc75316 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Sat, 7 Aug 2021 19:45:47 +0000 Subject: [PATCH] Fixing synchronization bug in ctl functionality --- fedilogue/ctl.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fedilogue/ctl.go b/fedilogue/ctl.go index f9a7af8..a1a3475 100644 --- a/fedilogue/ctl.go +++ b/fedilogue/ctl.go @@ -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) }