From 904f1a31703c3d8e8551766460c752a0b4a4e69a Mon Sep 17 00:00:00 2001
From: Benjamin Wenger <ben@elixxir.ioo>
Date: Thu, 23 Sep 2021 08:55:33 -0700
Subject: [PATCH] fixed a crash and message pickup bugs

---
 cmd/root.go                |  5 ++++-
 network/gateway/sender.go  | 20 ++++++++++++++++----
 network/rounds/retrieve.go |  5 +++--
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/cmd/root.go b/cmd/root.go
index 8017177e1..853b5a48c 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -247,7 +247,10 @@ var rootCmd = &cobra.Command{
 			}
 		}
 		fmt.Printf("Received %d\n", receiveCnt)
-		roundsNotepad.INFO.Printf("\n%s", client.GetNetworkInterface().GetVerboseRounds())
+		if roundsNotepad!=nil{
+			roundsNotepad.INFO.Printf("\n%s", client.GetNetworkInterface().GetVerboseRounds())
+		}
+
 		err = client.StopNetworkFollower()
 		if err != nil {
 			jww.WARN.Printf(
diff --git a/network/gateway/sender.go b/network/gateway/sender.go
index 1ae30ccea..693fdf058 100644
--- a/network/gateway/sender.go
+++ b/network/gateway/sender.go
@@ -26,6 +26,8 @@ type Sender struct {
 	*HostPool
 }
 
+const RetryableError = "Nonfatal error occurred, please retry"
+
 // NewSender Create a new Sender object wrapping a HostPool object
 func NewSender(poolParams PoolParams, rng *fastRNG.StreamGenerator, ndf *ndf.NetworkDefinition, getter HostManager,
 	storage *storage.Session, addGateway chan network.NodeGateway) (*Sender, error) {
@@ -47,10 +49,12 @@ func (s *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error
 			return nil, errors.Errorf(stoppable.ErrMsg, stop.Name(), "SendToAny")
 		}else if err==nil{
 			return result, nil
-		} else if strings.Contains(err.Error(),"unable to connect to target host") {
+		} else if strings.Contains(err.Error(), RetryableError) {
 			// Retry of the proxy could not communicate
-			jww.WARN.Printf("Unable to SendToAny via %s: proxy could not contact requested host: %s",
+			jww.INFO.Printf("Unable to SendToAny via %s: non-fatal error received, retrying: %s",
 				proxies[proxy].GetId().String(), err)
+		}else if strings.Contains(err.Error(),"unable to connect to target host") {
+
 		}else if replaced, checkReplaceErr := s.checkReplace(proxies[proxy].GetId(), err); replaced{
 			if checkReplaceErr!=nil{
 				jww.WARN.Printf("Unable to SendToAny, replaced a proxy %s with error %s",
@@ -82,7 +86,11 @@ func (s *Sender) SendToPreferred(targets []*id.ID,
 			return nil, errors.Errorf(stoppable.ErrMsg, stop.Name(), "SendToPreferred")
 		} else if err == nil {
 			return result, nil
-		} else if strings.Contains(err.Error(),"unable to connect to target host") {
+		} else if strings.Contains(err.Error(), RetryableError) {
+			// Retry of the proxy could not communicate
+			jww.INFO.Printf("Unable to to SendToPreferred first pass %s via %s: non-fatal error received, retrying: %s",
+				targets[i], targetHosts[i].GetId(), err)
+		}else if strings.Contains(err.Error(),"unable to connect to target host") {
 			// Retry of the proxy could not communicate
 			jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s: %s, " +
 				"proxy could not contact requested host",
@@ -141,7 +149,11 @@ func (s *Sender) SendToPreferred(targets []*id.ID,
 				return nil, errors.Errorf(stoppable.ErrMsg, stop.Name(), "SendToPreferred")
 			} else if err == nil {
 				return result, nil
-			} else if strings.Contains(err.Error(),"unable to connect to target host") {
+			} else if strings.Contains(err.Error(), RetryableError) {
+				// Retry of the proxy could not communicate
+				jww.INFO.Printf("Unable to SendToPreferred second pass %s via %s: non-fatal error received, retrying: %s",
+					target, proxy, err)
+			}else if strings.Contains(err.Error(),"unable to connect to target host") {
 				// Retry of the proxy could not communicate
 				jww.WARN.Printf("Unable to SendToPreferred second pass %s via %s: %s," +
 					" proxy could not contact requested host",
diff --git a/network/rounds/retrieve.go b/network/rounds/retrieve.go
index bd7f1d682..cf1584a8d 100644
--- a/network/rounds/retrieve.go
+++ b/network/rounds/retrieve.go
@@ -11,6 +11,7 @@ import (
 	"encoding/binary"
 	"github.com/pkg/errors"
 	jww "github.com/spf13/jwalterweatherman"
+	"gitlab.com/elixxir/client/network/gateway"
 	"gitlab.com/elixxir/client/network/message"
 	"gitlab.com/elixxir/client/stoppable"
 	"gitlab.com/elixxir/client/storage/reception"
@@ -157,8 +158,8 @@ func (m *Manager) getMessagesFromGateway(roundID id.Round,
 		// If the gateway doesnt have the round, return an error
 		msgResp, err := comms.RequestMessages(host, msgReq)
 		if err == nil && !msgResp.GetHasRound() {
-			jww.INFO.Printf("No round error for round %d received from %s", roundID, target)
-			return message.Bundle{}, errors.Errorf(noRoundError, roundID)
+			errRtn := errors.Errorf(noRoundError, roundID)
+			return message.Bundle{}, errors.WithMessage(errRtn,gateway.RetryableError)
 		}
 
 		return msgResp, err
-- 
GitLab