mirror of https://github.com/grpc/grpc-go.git
xds/client: hold authority mutex before making a new authority (#5331)
This commit is contained in:
parent
de73b2b645
commit
78b13f27de
|
|
@ -55,7 +55,7 @@ func (c *clientImpl) findAuthority(n *xdsresource.Name) (_ *authority, unref fun
|
|||
config = cfg.XDSServer
|
||||
}
|
||||
|
||||
a, err := c.newAuthority(config)
|
||||
a, err := c.newAuthorityLocked(config)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("xds: failed to connect to the control plane for authority %q: %v", authority, err)
|
||||
}
|
||||
|
|
@ -73,14 +73,14 @@ func (c *clientImpl) findAuthority(n *xdsresource.Name) (_ *authority, unref fun
|
|||
return a, func() { c.unrefAuthority(a) }, nil
|
||||
}
|
||||
|
||||
// newAuthority creates a new authority for the config. But before that, it
|
||||
// newAuthorityLocked creates a new authority for the config. But before that, it
|
||||
// checks the cache to see if an authority for this config already exists.
|
||||
//
|
||||
// The caller must take a reference of the returned authority before using, and
|
||||
// unref afterwards.
|
||||
//
|
||||
// caller must hold c.authorityMu
|
||||
func (c *clientImpl) newAuthority(config *bootstrap.ServerConfig) (_ *authority, retErr error) {
|
||||
func (c *clientImpl) newAuthorityLocked(config *bootstrap.ServerConfig) (_ *authority, retErr error) {
|
||||
// First check if there's already an authority for this config. If found, it
|
||||
// means this authority is used by other watches (could be the same
|
||||
// authority name, or a different authority name but the same server
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ import (
|
|||
// It returns a Store for the user to report loads, a function to cancel the
|
||||
// load reporting stream.
|
||||
func (c *clientImpl) ReportLoad(server *bootstrap.ServerConfig) (*load.Store, func()) {
|
||||
a, err := c.newAuthority(server)
|
||||
c.authorityMu.Lock()
|
||||
a, err := c.newAuthorityLocked(server)
|
||||
c.authorityMu.Unlock()
|
||||
if err != nil {
|
||||
c.logger.Infof("xds: failed to connect to the control plane to do load reporting for authority %q: %v", server, err)
|
||||
return nil, func() {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue