From 243ef5d7ee104afd30f76ff8838135a5044eb2e6 Mon Sep 17 00:00:00 2001
From: Benjamin Wenger <ben@elixxir.ioo>
Date: Thu, 8 Apr 2021 19:30:56 -0700
Subject: [PATCH] fixes logspam issues

---
 bindings/client.go        | 41 +++++++--------------------------------
 network/health/tracker.go |  2 +-
 2 files changed, 8 insertions(+), 35 deletions(-)

diff --git a/bindings/client.go b/bindings/client.go
index 2ebc43897..391aa361c 100644
--- a/bindings/client.go
+++ b/bindings/client.go
@@ -36,7 +36,6 @@ func init() {
 // to support the gomobile Client interface
 type Client struct {
 	api api.Client
-	waitForNetwork chan bool
 }
 
 // NewClient creates client storage, generates keys, connects, and registers
@@ -225,41 +224,15 @@ func (c *Client) StopNetworkFollower(timeoutMS int) error {
 // WaitForNewtwork will block until either the network is healthy or the
 // passed timeout. It will return true if the network is healthy
 func (c *Client) WaitForNetwork(timeoutMS int) bool {
-	timeout := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
-	if c.waitForNetwork == nil{
-		c.waitForNetwork = make(chan bool, 1)
-		c.api.GetHealth().AddChannel(c.waitForNetwork)
-	}
-
-	//flush the channel if it is already full
-	select{
-	case <- c.waitForNetwork:
-	default:
-	}
-
-	// start a thread to check if healthy in a second in order to handle
-	// race conditions
-	go func() {
-		time.Sleep(1*time.Second)
-		if c.api.GetHealth().IsHealthy() {
-			select{
-			case c.waitForNetwork<-true:
-			default:
-			}
-		}
-	}()
-
-	//wait for network to be healthy or the timer to time out
-	for  {
-		select{
-		case result := <- c.waitForNetwork:
-			if result {
-				return true
-			}
-		case <-timeout.C:
-			return false
+	start := time.Now()
+	timeout := time.Duration(timeoutMS)*time.Millisecond
+	for time.Now().Sub(start)<timeout{
+		if c.api.GetHealth().IsHealthy(){
+			return true
 		}
+		time.Sleep(250*time.Millisecond)
 	}
+	return false
 }
 
 // Gets the state of the network follower. Returns:
diff --git a/network/health/tracker.go b/network/health/tracker.go
index 7779a86b9..ff53904f2 100644
--- a/network/health/tracker.go
+++ b/network/health/tracker.go
@@ -159,7 +159,7 @@ func (t *Tracker) transmit(health bool) {
 		select {
 		case c <- health:
 		default:
-			jww.WARN.Printf("Unable to send Health event")
+			jww.DEBUG.Printf("Unable to send Health event")
 		}
 	}
 
-- 
GitLab