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 endless waiting in liveness check #788

Merged
merged 4 commits into from
Dec 29, 2023
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
50 changes: 26 additions & 24 deletions pkg/tools/heal/liveness_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ const (
intervalFactor = 0.85
)

func waitForResponses(responseCh <-chan error) bool {
func waitForResponses(ctx context.Context, responseCh <-chan error) bool {
respCount := cap(responseCh)
success := true
for {
resp, ok := <-responseCh
if !ok {
select {
case <-ctx.Done():
return false
}
if resp != nil {
success = false
}
respCount--
if respCount == 0 {
return success
case resp, ok := <-responseCh:
if !ok {
return false
}
if resp != nil {
success = false
}
respCount--
if respCount == 0 {
return success
}
}
}
}
Expand Down Expand Up @@ -103,20 +107,18 @@ func doPing(
}
defer func() { _ = subscription.Unsubscribe() }()

for {
select {
case <-deadlineCtx.Done():
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
return
}
responseCh <- nil
select {
case <-deadlineCtx.Done():
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
return
}
responseCh <- nil
}
}
}
Expand Down Expand Up @@ -169,6 +171,6 @@ func VPPLivenessCheck(vppConn vpphelper.Connection) func(deadlineCtx context.Con
}

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