Skip to content

Commit

Permalink
fixup! Add length check before accessing in round robin
Browse files Browse the repository at this point in the history
Signed-off-by: dahuang <[email protected]>
  • Loading branch information
dahuang-purestorage committed Jan 11, 2024
1 parent 63a271c commit a0a02a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pkg/loadbalancer/roundrobin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/loadbalancer/roundrobin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a0a02a3

Please sign in to comment.