Skip to content

Commit

Permalink
fix: fatal error: concurrent map writes (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
plopezlpz committed Dec 11, 2024
1 parent 6550ff3 commit d67f7df
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions waku/v2/protocol/store/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math"
"sync"

"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -73,6 +74,7 @@ type WakuStore struct {

defaultRatelimit rate.Limit
rateLimiters map[peer.ID]*rate.Limiter
rateLimitersMux sync.Mutex
}

// NewWakuStore is used to instantiate a StoreV3 client
Expand Down Expand Up @@ -297,11 +299,13 @@ func (s *WakuStore) queryFrom(ctx context.Context, storeRequest *pb.StoreQueryRe
logger.Debug("sending store request")

if !params.skipRatelimit {
s.rateLimitersMux.Lock()
rateLimiter, ok := s.rateLimiters[params.selectedPeer]
if !ok {
rateLimiter = rate.NewLimiter(s.defaultRatelimit, 1)
s.rateLimiters[params.selectedPeer] = rateLimiter
}
s.rateLimitersMux.Unlock()
err := rateLimiter.Wait(ctx)
if err != nil {
return nil, err
Expand Down

0 comments on commit d67f7df

Please sign in to comment.