client/metadata: fix crasher caused by AllowStale = false (#16549)

Fixes #16517

Given a 3 Server cluster with at least 1 Client connected to Follower 1:

If a NodeMeta.{Apply,Read} for the Client request is received by
Follower 1 with `AllowStale = false` the Follower will forward the
request to the Leader.

The Leader, not being connected to the target Client, will forward the
RPC to Follower 1.

Follower 1, seeing AllowStale=false, will forward the request to the
Leader.

The Leader, not being connected to... well hoppefully you get the
picture: an infinite loop occurs.
This commit is contained in:
Michael Schurter
2023-03-20 16:32:32 -07:00
committed by GitHub
parent 695df42d33
commit fb085186b7
13 changed files with 197 additions and 31 deletions

View File

@@ -143,15 +143,16 @@ func WaitForLeader(t testing.TB, rpc rpcFn) {
})
}
// WaitForLeaders blocks until each serverRPC knows the leader.
func WaitForLeaders(t testing.TB, serverRPCs ...rpcFn) {
// WaitForLeaders blocks until each rpcs knows the leader.
func WaitForLeaders(t testing.TB, rpcs ...rpcFn) string {
t.Helper()
for i := 0; i < len(serverRPCs); i++ {
var leader string
for i := 0; i < len(rpcs); i++ {
ok := func() (bool, error) {
leader = ""
args := &structs.GenericRequest{}
var leader string
err := serverRPCs[i]("Status.Leader", args, &leader)
err := rpcs[i]("Status.Leader", args, &leader)
return leader != "", err
}
must.Wait(t, wait.InitialSuccess(
@@ -160,6 +161,8 @@ func WaitForLeaders(t testing.TB, serverRPCs ...rpcFn) {
wait.Gap(1*time.Second),
))
}
return leader
}
// WaitForClient blocks until the client can be found