fix: data race in peer connector

This commit is contained in:
Prem Chaitanya Prathi 2023-08-07 14:42:48 +05:30
parent 20040f2e9b
commit baeaa1dd55
No known key found for this signature in database
1 changed files with 2 additions and 0 deletions

View File

@ -301,7 +301,9 @@ func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) {
c.wg.Add(1)
go func(pi peer.AddrInfo) {
defer c.wg.Done()
c.RLock()
ctx, cancel := context.WithTimeout(c.workerCtx, c.dialTimeout)
c.RUnlock()
defer cancel()
err := c.host.Connect(ctx, pi)
if err != nil && !errors.Is(err, context.Canceled) {