Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miparnisari committed Feb 20, 2024
1 parent 5c0e54e commit 2b940a8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions peer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ func (c *PeerClient) GetPeerRateLimits(ctx context.Context, r *GetPeerRateLimits
// a race condition if called within a separate go routine if the internal wg is `0`
// when Wait() is called then Add(1) is called concurrently.
c.wgMutex.Lock()
defer c.wgMutex.Unlock() // unlock at the very end of this function
c.wg.Add(1)
c.wgMutex.Unlock()
defer c.wg.Done()

c.clientMutex.RLock()
Expand Down Expand Up @@ -247,8 +247,8 @@ func (c *PeerClient) UpdatePeerGlobals(ctx context.Context, r *UpdatePeerGlobals

// See NOTE above about RLock and wg.Add(1)
c.wgMutex.Lock()
defer c.wgMutex.Unlock() // unlock at the very end of this function
c.wg.Add(1)
c.wgMutex.Unlock()
defer c.wg.Done()

c.clientMutex.RLock()
Expand Down Expand Up @@ -317,8 +317,8 @@ func (c *PeerClient) getPeerRateLimitsBatch(ctx context.Context, r *RateLimitReq
}

c.wgMutex.Lock()
defer c.wgMutex.Unlock() // unlock at the very end of this function
c.wg.Add(1)
c.wgMutex.Unlock()
defer c.wg.Done()

// Enqueue the request to be sent
Expand Down Expand Up @@ -486,9 +486,9 @@ func (c *PeerClient) Shutdown() {
c.statusMutex.Unlock()

// drain in-flight requests
c.wgMutex.RLock()
c.wgMutex.Lock()
defer c.wgMutex.Unlock()
c.wg.Wait()
c.wgMutex.RUnlock()

// no more items will be sent
close(c.queue)
Expand Down

0 comments on commit 2b940a8

Please sign in to comment.