Skip to content

Commit

Permalink
fix data race in client (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyang0 authored Sep 11, 2023
1 parent f52c5e3 commit 923b308
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type PoolConfig struct {

// Pool implement of RPCClientPool
type Pool struct {
mu sync.Mutex
rpcClients []*clientWithStatus
}

Expand Down Expand Up @@ -81,6 +82,9 @@ func NewCoreRPCClientPool(ctx context.Context, config *PoolConfig) (*Pool, error

// GetClient finds the first *client.Client instance with an active connection. If all connections are dead, returns the first one.
func (c *Pool) GetClient() pb.CoreRPCClient {
c.mu.Lock()
defer c.mu.Unlock()

for _, rpc := range c.rpcClients {
if rpc.alive {
return rpc.client
Expand All @@ -104,6 +108,9 @@ func checkAlive(ctx context.Context, rpc *clientWithStatus, timeout time.Duratio
}

func (c *Pool) updateClientsStatus(ctx context.Context, timeout time.Duration) {
c.mu.Lock()
defer c.mu.Unlock()

wg := &sync.WaitGroup{}
defer wg.Wait()
for _, rpc := range c.rpcClients {
Expand Down

0 comments on commit 923b308

Please sign in to comment.