From b86ccc1415e81db4fe4262754c06e692601153a7 Mon Sep 17 00:00:00 2001 From: Jake Taylor <jake@elixxir.io> Date: Fri, 3 Jun 2022 17:48:37 -0500 Subject: [PATCH] fix mutex --- cmix/gateway/hostPool.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmix/gateway/hostPool.go b/cmix/gateway/hostPool.go index 25dc7192e..71fcbe187 100644 --- a/cmix/gateway/hostPool.go +++ b/cmix/gateway/hostPool.go @@ -358,16 +358,16 @@ func (h *HostPool) UpdateNdf(ndf *ndf.NetworkDefinition) { return } + // Lock order is extremely important here + h.hostMux.Lock() h.ndfMux.Lock() h.ndf = ndf.DeepCopy() - - h.hostMux.Lock() err := h.updateConns() - h.hostMux.Unlock() if err != nil { jww.ERROR.Printf("Unable to updateConns: %+v", err) } h.ndfMux.Unlock() + h.hostMux.Unlock() } // SetGatewayFilter sets the filter used to filter gateways from the ID map. @@ -506,8 +506,9 @@ func (h *HostPool) checkReplace(hostId *id.ID, hostErr error) (bool, error) { } } + // If the Host is still in the pool if doReplace { - // If the Host is still in the pool + // Lock order is extremely important here h.hostMux.Lock() if oldPoolIndex, ok := h.hostMap[*hostId]; ok { // Replace it -- GitLab