From 7b3b9672f649e2b56341b46c484dad3f634150b4 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Tue, 13 Apr 2021 14:04:49 -0700 Subject: [PATCH] added the transmit mux to stop disconnects while operations are ongoing with the host --- connect/host.go | 5 +++-- connect/transmit.go | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/connect/host.go b/connect/host.go index f0a7445..fb30a4f 100644 --- a/connect/host.go +++ b/connect/host.go @@ -82,6 +82,7 @@ type Host struct { // Send lock sendMux sync.RWMutex + transmitMux sync.RWMutex coolOffBucket *rateLimiting.Bucket inCoolOff bool @@ -221,8 +222,8 @@ func (h *Host) SetMetricsTesting(m *Metric, face interface{}) { // Disconnect closes a the Host connection under the write lock func (h *Host) Disconnect() { - h.sendMux.Lock() - defer h.sendMux.Unlock() + h.transmitMux.Lock() + defer h.transmitMux.Unlock() h.disconnect() } diff --git a/connect/transmit.go b/connect/transmit.go index 0c59de7..e4fee8d 100644 --- a/connect/transmit.go +++ b/connect/transmit.go @@ -27,6 +27,9 @@ func (c *ProtoComms) transmit(host *Host, f func(conn *grpc.ClientConn) (interfa return nil, errors.New("Host address is blank, host might be receive only.") } + host.transmitMux.RLock() + defer host.transmitMux.RUnlock() + for numRetries := 0; numRetries < MaxRetries; numRetries++ { err = nil //reconnect if necessary -- GitLab