fix potential race condition: reading from a nil channel

This commit is contained in:
Travis Turner 2018-01-23 16:32:32 -06:00
parent f12527d535
commit 0cb8b77640
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9

View file

@ -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