rpc: set response to nil when not found

Otherwise when the query times out we might incorrectly send a value for
the reply, when we should send an empty reply.

Also document errNotFound and how to handle the result in that case.
This commit is contained in:
Daniel Nephin 2022-02-18 12:13:23 -05:00
parent 85ecbaf109
commit dc484ee09e
3 changed files with 13 additions and 7 deletions

View File

@ -205,12 +205,10 @@ func (c *ConfigEntry) Get(args *structs.ConfigEntryQuery, reply *structs.ConfigE
return err
}
reply.Index = index
reply.Index, reply.Entry = index, entry
if entry == nil {
return errNotFound
}
reply.Entry = entry
return nil
})
}

View File

@ -122,12 +122,10 @@ func (c *FederationState) Get(args *structs.FederationStateQuery, reply *structs
return err
}
reply.Index = index
reply.Index, reply.State = index, fedState
if fedState == nil {
return errNotFound
}
reply.State = fedState
return nil
})
}

View File

@ -945,7 +945,17 @@ type blockingQueryResponseMeta interface {
//
// The query function is expected to be a closure that has access to responseMeta
// so that it can set the Index. The actual result of the query is opaque to blockingQuery.
// If query function returns an error, the error is returned to the caller immediately.
//
// The query function can return errNotFound, which is a sentinel error. Returning
// errNotFound indicates that the query found no results, which allows
// blockingQuery to keep blocking until the query returns a non-nil error.
// The query function must take care to set the actual result of the query to
// nil in these cases, otherwise when blockingQuery times out it may return
// a previous result. errNotFound will never be returned to the caller, it is
// converted to nil before returning.
//
// If query function returns any other error, the error is returned to the caller
// immediately.
//
// The query function must follow these rules:
//