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: [NPM] [Linux] panic if applyIPSets continues to fail #2964

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
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
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
Loading