diff --git a/pkg/loadbalancer/roundrobin.go b/pkg/loadbalancer/roundrobin.go index 7517b5f24..eba62e256 100644 --- a/pkg/loadbalancer/roundrobin.go +++ b/pkg/loadbalancer/roundrobin.go @@ -98,6 +98,9 @@ func (rr *roundRobin) GetRemoteNode() (string, bool, error) { // Get target node info and set next round robbin node. // nextNode is always lastNode + 1 mod (numOfNodes), to loop back to zero targetNodeEndpoint, isRemoteConn := rr.getTargetAndIncrement(filteredNodes, selfNode.Id) + if targetNodeEndpoint == "" { + return "", false, errors.New("target node not found") + } return targetNodeEndpoint, isRemoteConn, nil } diff --git a/pkg/loadbalancer/roundrobin_test.go b/pkg/loadbalancer/roundrobin_test.go index c0f967abb..4f4e4776a 100644 --- a/pkg/loadbalancer/roundrobin_test.go +++ b/pkg/loadbalancer/roundrobin_test.go @@ -94,12 +94,10 @@ func TestGetRemoteNodeWithDomains(t *testing.T) { } } -// TestGetTargetAndIncrementNullPointer tests the case when getTargetAndIncrement -// causes null pointer. This happens when the round robin index is not checked against node array -// length before accessing it. -// -// https://portworx.atlassian.net/browse/PWX-35601 -func TestGetTargetAndIncrementNullPointer(t *testing.T) { +// TestGetTargetAndIncrementIndexOutOfBound tests the case when getTargetAndIncrement +// causes index out of bound error. This happens when the round robin index is not +// checked against node array length before accessing it. +func TestGetTargetAndIncrementIndexOutOfBound(t *testing.T) { filteredNodes := []*api.Node{ { Id: "1",