Skip to content

Commit

Permalink
Fix panic in vpp liveness check (#790)
Browse files Browse the repository at this point in the history
* fix panic in vpp liveness check

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

* fix golang linter

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

---------

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik authored Jan 11, 2024
1 parent 147ddfd commit 0739c25
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions pkg/tools/heal/liveness_check.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -36,24 +36,20 @@ const (
intervalFactor = 0.85
)

func waitForResponses(ctx context.Context, responseCh <-chan error) bool {
func waitForResponses(responseCh <-chan bool) bool {
respCount := cap(responseCh)
success := true
for {
select {
case <-ctx.Done():
resp, ok := <-responseCh
if !ok {
return false
case resp, ok := <-responseCh:
if !ok {
return false
}
if resp != nil {
success = false
}
respCount--
if respCount == 0 {
return success
}
}
if !resp {
success = false
}
respCount--
if respCount == 0 {
return success
}
}
}
Expand Down Expand Up @@ -89,36 +85,36 @@ func doPing(
srcIP, dstIP ip_types.Address,
interval float64,
repeat uint32,
responseCh chan error) {
responseCh chan bool) {
logger := log.FromContext(deadlineCtx).WithField("srcIP", srcIP.String()).WithField("dstIP", dstIP.String())

apiChannel, err := getAPIChannel(deadlineCtx, vppConn, dstIP, interval, repeat)
if err != nil {
responseCh <- nil
responseCh <- true
return
}

notifCh := make(chan api.Message, 256)
subscription, err := apiChannel.SubscribeNotification(notifCh, &ping.PingFinishedEvent{})
if err != nil {
logger.Error(errors.Wrap(err, "failed to subscribe for receiving of the specified notification messages via provided Go channel").Error())
responseCh <- nil
responseCh <- true
return
}
defer func() { _ = subscription.Unsubscribe() }()

select {
case <-deadlineCtx.Done():
responseCh <- true
return
case rawMsg := <-notifCh:
if msg, ok := rawMsg.(*ping.PingFinishedEvent); ok {
if msg.ReplyCount == 0 {
err = errors.New("No packets received")
logger.Errorf(err.Error())
responseCh <- err
logger.Errorf("No packets received")
responseCh <- false
return
}
responseCh <- nil
responseCh <- true
}
}
}
Expand Down Expand Up @@ -162,7 +158,7 @@ func VPPLivenessCheck(vppConn vpphelper.Connection) func(deadlineCtx context.Con
return true
}

responseCh := make(chan error, combinationCount)
responseCh := make(chan bool, combinationCount)
defer close(responseCh)
for _, srcIP := range srcIPs {
for _, dstIP := range dstIPs {
Expand All @@ -171,6 +167,6 @@ func VPPLivenessCheck(vppConn vpphelper.Connection) func(deadlineCtx context.Con
}

// Waiting for all ping results. If at least one fails - return false
return waitForResponses(deadlineCtx, responseCh)
return waitForResponses(responseCh)
}
}

0 comments on commit 0739c25

Please sign in to comment.