mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-28 04:10:44 -04:00
Eliminate a race stemming from each core's monitoring goroutine sharing the client for the active node. (#7255)
This commit is contained in:
parent
e0cb9df924
commit
f492f3c736
1 changed files with 26 additions and 19 deletions
|
|
@ -650,37 +650,44 @@ func WaitForActiveNodeAndPerfStandbys(t testing.T, cluster *vault.TestCluster) {
|
|||
var standbys, actives int64
|
||||
var wg sync.WaitGroup
|
||||
deadline := time.Now().Add(30 * time.Second)
|
||||
for _, c := range cluster.Cores {
|
||||
for i, c := range cluster.Cores {
|
||||
wg.Add(1)
|
||||
go func(client *api.Client) {
|
||||
go func(coreIdx int, client *api.Client) {
|
||||
defer wg.Done()
|
||||
val := 1
|
||||
for time.Now().Before(deadline) {
|
||||
_, err = cluster.Cores[0].Client.Logical().Write(path, map[string]interface{}{
|
||||
"bar": val,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("unable to write KV", "path", path)
|
||||
if coreIdx == 0 {
|
||||
_, err = cluster.Cores[0].Client.Logical().Write(path, map[string]interface{}{
|
||||
"bar": val,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("unable to write KV", "path", path)
|
||||
}
|
||||
}
|
||||
val++
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
leader, err := client.Sys().Leader()
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "Vault is sealed") {
|
||||
continue
|
||||
|
||||
if coreIdx > 0 || atomic.LoadInt64(&actives) == 0 {
|
||||
leader, err := client.Sys().Leader()
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "Vault is sealed") {
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if leader.IsSelf {
|
||||
atomic.AddInt64(&actives, 1)
|
||||
}
|
||||
if leader.PerfStandby && leader.PerfStandbyLastRemoteWAL > 0 {
|
||||
atomic.AddInt64(&standbys, 1)
|
||||
return
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if leader.IsSelf {
|
||||
atomic.AddInt64(&actives, 1)
|
||||
return
|
||||
}
|
||||
if leader.PerfStandby && leader.PerfStandbyLastRemoteWAL > 0 {
|
||||
atomic.AddInt64(&standbys, 1)
|
||||
if coreIdx == 0 && int(atomic.LoadInt64(&standbys)) == len(cluster.Cores)-1 {
|
||||
return
|
||||
}
|
||||
}
|
||||
}(c.Client)
|
||||
}(i, c.Client)
|
||||
}
|
||||
wg.Wait()
|
||||
if actives != 1 || int(standbys) != len(cluster.Cores)-1 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue