From 0cb8b776403d81912972cda11275b32497b100af Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Tue, 23 Jan 2018 16:32:32 -0600 Subject: [PATCH] fix potential race condition: reading from a nil channel --- test/cluster.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/cluster.go b/test/cluster.go index f7f4530ef..ebe48fd35 100644 --- a/test/cluster.go +++ b/test/cluster.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "path/filepath" "sort" + "sync" "time" "github.com/gogo/protobuf/proto" @@ -77,6 +78,8 @@ type TestCluster struct { common *commonClusterSettings + mu sync.RWMutex + resizing bool resizeDone chan struct{} } @@ -186,6 +189,9 @@ func (t *TestCluster) AddNode(saveTopology bool) error { // Wait for the AddNode job to finish. if c.State() != pilosa.ClusterStateNormal { t.resizeDone = make(chan struct{}) + t.mu.Lock() + t.resizing = true + t.mu.Unlock() <-t.resizeDone } } @@ -314,9 +320,11 @@ func (t *TestCluster) SendSync(pb proto.Message) error { for _, c := range t.Clusters { c.MergeClusterStatus(obj) } - if obj.State == pilosa.ClusterStateNormal && t.resizeDone != nil { + t.mu.RLock() + if obj.State == pilosa.ClusterStateNormal && t.resizing { close(t.resizeDone) } + t.mu.RUnlock() } return nil