Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data race in client #611

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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