Skip to content

Commit e4436da

Browse files
[backport] fix: [NPM] [Linux] panic if applyIPSets continues to fail (#2969)
[backport] fix: [NPM] [Linux] panic if applyIPSets continues to fail (#2964) Signed-off-by: Hunter Gregory <[email protected]>
1 parent e43adc3 commit e4436da

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

npm/pkg/dataplane/ipsets/ipsetmanager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type IPSetManager struct {
5151
setMap map[string]*IPSet
5252
dirtyCache dirtyCacheInterface
5353
ioShim *common.IOShim
54+
// consecutiveApplyFailures is used in Linux to count the number of consecutive failures to apply ipsets
55+
// if this count exceeds a threshold, we will panic
56+
consecutiveApplyFailures int
5457
sync.RWMutex
5558
}
5659

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

npm/pkg/dataplane/ipsets/ipsetmanager_linux.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const (
5454
destroySectionPrefix = "delete"
5555
addOrUpdateSectionPrefix = "add/update"
5656
ipsetRestoreLineFailurePattern = "Error in line (\\d+):"
57+
58+
maxConsecutiveFailures = 100
5759
)
5860

5961
var (
@@ -408,8 +410,19 @@ func (iMgr *IPSetManager) applyIPSets() error {
408410
creator := iMgr.fileCreatorForApply(maxTryCount)
409411
restoreError := creator.RunCommandWithFile(ipsetCommand, ipsetRestoreFlag)
410412
if restoreError != nil {
413+
iMgr.consecutiveApplyFailures++
414+
if iMgr.consecutiveApplyFailures >= maxConsecutiveFailures {
415+
msg := fmt.Sprintf("exceeded max consecutive failures (%d) when applying ipsets. final error: %s", maxConsecutiveFailures, restoreError.Error())
416+
klog.Error(msg)
417+
metrics.SendErrorLogAndMetric(util.IpsmID, msg)
418+
panic(msg)
419+
}
420+
411421
return npmerrors.SimpleErrorWrapper("ipset restore failed when applying ipsets", restoreError)
412422
}
423+
424+
iMgr.consecutiveApplyFailures = 0
425+
413426
return nil
414427
}
415428

0 commit comments

Comments
 (0)