Skip to content

Commit

Permalink
[backport] fix: [NPM] [Linux] panic if applyIPSets continues to fail (#…
Browse files Browse the repository at this point in the history
…2969)

[backport] fix: [NPM] [Linux] panic if applyIPSets continues to fail (#2964)

Signed-off-by: Hunter Gregory <42728408+huntergregory@users.noreply.github.com>
  • Loading branch information
huntergregory authored Aug 28, 2024
1 parent e43adc3 commit 2dcb1c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 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
sync.RWMutex
}

Expand All @@ -71,6 +74,8 @@ func NewIPSetManager(iMgrCfg *IPSetManagerCfg, ioShim *common.IOShim) *IPSetMana
setMap: make(map[string]*IPSet),
dirtyCache: newDirtyCache(),
ioShim: ioShim,
// set to 0 to avoid lint error for windows
consecutiveApplyFailures: 0,
}
}

Expand Down
13 changes: 13 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,19 @@ func (iMgr *IPSetManager) applyIPSets() error {
creator := iMgr.fileCreatorForApply(maxTryCount)
restoreError := creator.RunCommandWithFile(ipsetCommand, ipsetRestoreFlag)
if restoreError != nil {
iMgr.consecutiveApplyFailures++
if iMgr.consecutiveApplyFailures >= maxConsecutiveFailures {
msg := fmt.Sprintf("exceeded max consecutive failures (%d) when applying ipsets. final error: %s", maxConsecutiveFailures, restoreError.Error())
klog.Error(msg)
metrics.SendErrorLogAndMetric(util.IpsmID, msg)
panic(msg)
}

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

iMgr.consecutiveApplyFailures = 0

return nil
}

Expand Down

0 comments on commit 2dcb1c3

Please sign in to comment.