Skip to content

Commit

Permalink
Merge pull request #72 from GoogleCloudPlatform/hide-lock
Browse files Browse the repository at this point in the history
chore: do not expose the mutex
  • Loading branch information
nimf authored Mar 11, 2024
2 parents 75b97b4 + 7bc50d6 commit b6d2d20
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions grpcgcp/gcp_multiendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func FromMEContext(ctx context.Context) (string, bool) {
// [GCPMultiEndpoint] implements [grpc.ClientConnInterface] and can be used
// as a [grpc.ClientConn] when creating gRPC clients.
type GCPMultiEndpoint struct {
sync.RWMutex
mu sync.RWMutex

defaultName string
mes map[string]multiendpoint.MultiEndpoint
Expand Down Expand Up @@ -255,11 +255,11 @@ func (mc *monitoredConn) notify(state connectivity.State) {
mc.gme.log.Infof("%q endpoint state changed to %v", mc.endpoint, state)
}
// Inform all multiendpoints.
mc.gme.RLock()
mc.gme.mu.RLock()
for _, me := range mc.gme.mes {
me.SetEndpointAvailability(mc.endpoint, state == connectivity.Ready)
}
mc.gme.RUnlock()
mc.gme.mu.RUnlock()
}

func (mc *monitoredConn) monitor(ctx context.Context) {
Expand Down Expand Up @@ -294,8 +294,8 @@ func (mc *monitoredConn) stopMonitoring() {
// - For an existing endpoint nothing will change (the connection pool will not be re-created,
// thus no connection credentials change, nor connection configuration change).
func (gme *GCPMultiEndpoint) UpdateMultiEndpoints(meOpts *GCPMultiEndpointOptions) error {
gme.Lock()
defer gme.Unlock()
gme.mu.Lock()
defer gme.mu.Unlock()
if _, ok := meOpts.MultiEndpoints[meOpts.Default]; !ok {
return fmt.Errorf("default MultiEndpoint %q missing options", meOpts.Default)
}
Expand Down

0 comments on commit b6d2d20

Please sign in to comment.