Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Pause and retry ipset deletion if it fails the first time #3851

Merged
merged 1 commit into from
Jan 18, 2021
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
17 changes: 15 additions & 2 deletions net/ipset/ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os/exec"
"strings"
"time"

"github.com/pkg/errors"
)
Expand All @@ -21,6 +22,8 @@ const (
ListSet = Type("list:set")
HashIP = Type("hash:ip")
HashNet = Type("hash:net")

DestroyRetrySleepMs = 100
)

type Interface interface {
Expand Down Expand Up @@ -153,12 +156,22 @@ func (i *ipset) FlushAll() error {

func (i *ipset) Destroy(ipsetName Name) error {
i.removeSetFromUsers(ipsetName)
return doExec("destroy", string(ipsetName))
err := doExec("destroy", string(ipsetName))
if err != nil {
time.Sleep(DestroyRetrySleepMs * time.Millisecond)
return doExec("destroy", string(ipsetName))
}
return err
}

func (i *ipset) DestroyAll() error {
i.users = make(map[entryKey]map[UID]struct{})
return doExec("destroy")
err := doExec("destroy")
if err != nil {
time.Sleep(DestroyRetrySleepMs * time.Millisecond)
return doExec("destroy")
}
return err
}

// Fetch a list of all existing sets with a given prefix
Expand Down