From 8a7303027508ce5be41fac4c4749ddb7e97cf193 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Fri, 28 Jun 2024 11:50:54 +0000 Subject: [PATCH] add mutex to handle datarace in hypervisor getAllVisorSummary method' --- pkg/visor/hypervisor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/visor/hypervisor.go b/pkg/visor/hypervisor.go index 20bb1b83c..8ebbfebde 100644 --- a/pkg/visor/hypervisor.go +++ b/pkg/visor/hypervisor.go @@ -62,6 +62,7 @@ type Hypervisor struct { dmsgC *dmsg.Client users *usermanager.UserManager mu *sync.RWMutex + vsMu *sync.RWMutex selfConn Conn logger *logging.Logger } @@ -95,6 +96,7 @@ func NewHypervisor(config visorconfig.HypervisorConfig, visor *Visor, dmsgC *dms dmsgC: dmsgC, users: usermanager.NewUserManager(mLogger, singleUserDB, config.Cookies), mu: new(sync.RWMutex), + vsMu: new(sync.RWMutex), selfConn: selfConn, logger: mLogger.PackageLogger("hypervisor"), } @@ -562,7 +564,9 @@ func (hv *Hypervisor) getAllVisorsSummary() http.HandlerFunc { } else { log.Trace("Obtained summary via RPC.") resp := makeSummaryResp(err == nil, false, summary) + hv.vsMu.Lock() summaries = append(summaries, resp) + hv.vsMu.Unlock() } wg.Done() }(pk, c)