mirror of
https://github.com/status-im/go-waku.git
synced 2025-02-26 20:10:44 +00:00
fix: set concurrent dials to 5
This commit is contained in:
parent
dc08c44804
commit
88d52d6417
@ -245,8 +245,18 @@ func (c *PeerConnectionStrategy) workPublisher(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
const maxActiveDials = 5
|
||||
|
||||
func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) {
|
||||
defer c.wg.Done()
|
||||
|
||||
maxGoRoutines := c.minPeers
|
||||
if maxGoRoutines > maxActiveDials {
|
||||
maxGoRoutines = maxActiveDials
|
||||
}
|
||||
|
||||
sem := make(chan struct{}, maxGoRoutines)
|
||||
|
||||
for {
|
||||
select {
|
||||
case pi, ok := <-c.dialCh:
|
||||
@ -281,13 +291,19 @@ func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) {
|
||||
}
|
||||
c.mux.Unlock()
|
||||
|
||||
dialCtx, dialCtxCancel := context.WithTimeout(c.workerCtx, c.dialTimeout)
|
||||
err := c.host.Connect(dialCtx, pi)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
c.host.Peerstore().(peers.WakuPeerstore).AddConnFailure(pi)
|
||||
c.logger.Info("connecting to peer", logging.HostID("peerID", pi.ID), zap.Error(err))
|
||||
}
|
||||
dialCtxCancel()
|
||||
sem <- struct{}{}
|
||||
c.wg.Add(1)
|
||||
go func(pi peer.AddrInfo) {
|
||||
defer c.wg.Done()
|
||||
ctx, cancel := context.WithTimeout(c.workerCtx, c.dialTimeout)
|
||||
defer cancel()
|
||||
err := c.host.Connect(ctx, pi)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
c.host.Peerstore().(peers.WakuPeerstore).AddConnFailure(pi)
|
||||
c.logger.Info("connecting to peer", logging.HostID("peerID", pi.ID), zap.Error(err))
|
||||
}
|
||||
<-sem
|
||||
}(pi)
|
||||
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user