Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic in vpp liveness check #790

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading