mirror of https://github.com/status-im/go-waku.git
Fix panic in peer manager (#714)
* fix: slice error for index out of bounds this commit fixes slicing `notConnectedPeers` array with 0 to a negative value of `numPeersToConnect` by first checking if `numPeersToConnect` are greater than 0
This commit is contained in:
parent
76b007163a
commit
7badb4a37b
|
@ -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??
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue