Skip to content

Commit

Permalink
fix: [NPM] [Linux] panic if applyIPSets continues to fail
Browse files Browse the repository at this point in the history
Signed-off-by: Hunter Gregory <42728408+huntergregory@users.noreply.github.com>
  • Loading branch information
huntergregory committed Aug 28, 2024
1 parent 6b05df1 commit 5527fc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions npm/pkg/dataplane/ipsets/ipsetmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type IPSetManager struct {
setMap map[string]*IPSet
dirtyCache dirtyCacheInterface
ioShim *common.IOShim
// consecutiveApplyFailures is used in Linux to count the number of consecutive failures to apply ipsets
// if this count exceeds a threshold, we will panic
consecutiveApplyFailures int

Check failure on line 56 in npm/pkg/dataplane/ipsets/ipsetmanager.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

field `consecutiveApplyFailures` is unused (unused)

Check failure on line 56 in npm/pkg/dataplane/ipsets/ipsetmanager.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

field `consecutiveApplyFailures` is unused (unused)
sync.RWMutex
}

Expand Down
12 changes: 12 additions & 0 deletions npm/pkg/dataplane/ipsets/ipsetmanager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const (
destroySectionPrefix = "delete"
addOrUpdateSectionPrefix = "add/update"
ipsetRestoreLineFailurePattern = "Error in line (\\d+):"

maxConsecutiveFailures = 100
)

var (
Expand Down Expand Up @@ -408,8 +410,18 @@ func (iMgr *IPSetManager) applyIPSets() error {
creator := iMgr.fileCreatorForApply(maxTryCount)
restoreError := creator.RunCommandWithFile(ipsetCommand, ipsetRestoreFlag)
if restoreError != nil {
iMgr.consecutiveApplyFailures++
if iMgr.consecutiveApplyFailures >= maxConsecutiveFailures {
klog.Errorf("exceeded max consecutive failures (%d) when applying ipsets", maxConsecutiveFailures)
metrics.SendErrorLogAndMetric(util.IpsmID, "exceeded max consecutive failures (%d) when applying ipsets", maxConsecutiveFailures)
panic(fmt.Sprintf("exceeded max consecutive failures when applying ipsets (%d)", maxConsecutiveFailures))
}

return npmerrors.SimpleErrorWrapper("ipset restore failed when applying ipsets", restoreError)
}

iMgr.consecutiveApplyFailures = 0

return nil
}

Expand Down

0 comments on commit 5527fc0

Please sign in to comment.