diff --git a/waku/v2/peermanager/peer_manager.go b/waku/v2/peermanager/peer_manager.go index e888c12a..5e99db7d 100644 --- a/waku/v2/peermanager/peer_manager.go +++ b/waku/v2/peermanager/peer_manager.go @@ -170,6 +170,10 @@ func (pm *PeerManager) connectToRelayPeers() { numPeersToConnect = notConnectedPeers.Len() - 1 } + if numPeersToConnect <= 0 { + return + } + pm.connectToPeers(notConnectedPeers[0:numPeersToConnect]) } //Else: Should we raise some sort of unhealthy event?? } diff --git a/waku/v2/peermanager/peer_manager_test.go b/waku/v2/peermanager/peer_manager_test.go index 15c2aedf..4f8bcbe1 100644 --- a/waku/v2/peermanager/peer_manager_test.go +++ b/waku/v2/peermanager/peer_manager_test.go @@ -151,3 +151,17 @@ func TestAdditionAndRemovalOfPeer(t *testing.T) { _, err = pm.SelectPeer(protocol2, nil, utils.Logger()) require.Error(t, err, utils.ErrNoPeersAvailable) } + +func TestConnectToRelayPeers(t *testing.T) { + defer func() { + if r := recover(); r != nil { + t.Errorf("TestConnectToRelayPeers panicked: %v", r) + } + }() + + _, pm, deferFn := initTest(t) + defer deferFn() + + pm.connectToRelayPeers() + +}