From 4fd94c23456ff6d3521b4be26a376fee3d28aac7 Mon Sep 17 00:00:00 2001 From: Anthony Laibe <491074+alaibe@users.noreply.github.com> Date: Wed, 9 Aug 2023 09:20:58 +0200 Subject: [PATCH] fix: concurrent client access --- rpc/client.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index d84a89682..a25c48a20 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -42,9 +42,10 @@ type Client struct { upstreamURL string UpstreamChainID uint64 - local *gethrpc.Client - upstream *chain.ClientWithFallback - rpcClients map[uint64]*chain.ClientWithFallback + local *gethrpc.Client + upstream *chain.ClientWithFallback + rpcClientsMutex sync.RWMutex + rpcClients map[uint64]*chain.ClientWithFallback router *router NetworkManager *network.Manager @@ -107,6 +108,8 @@ func (c *Client) SetWalletNotifier(notifier func(chainID uint64, message string) } func (c *Client) getClientUsingCache(chainID uint64) (*chain.ClientWithFallback, error) { + c.rpcClientsMutex.Lock() + defer c.rpcClientsMutex.Unlock() if rpcClient, ok := c.rpcClients[chainID]; ok { if rpcClient.WalletNotifier == nil { rpcClient.WalletNotifier = c.walletNotifier