From 8a5e3b7e674a7b342b254b48cd36a439134ceb0e Mon Sep 17 00:00:00 2001
From: pablo
Date: Tue, 10 Dec 2024 12:33:22 +0200
Subject: [PATCH] fix: fatal error: concurrent map writes
---
waku/v2/protocol/store/client.go | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/waku/v2/protocol/store/client.go b/waku/v2/protocol/store/client.go
index febb863e5..efb6448b9 100644
--- a/waku/v2/protocol/store/client.go
+++ b/waku/v2/protocol/store/client.go
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math"
+ "sync"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
@@ -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
@@ -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