Merge pull request #3851 from NeonSludge/fix-ipset-destroy

Pause and retry ipset deletion if it fails the first time
This commit is contained in:
Bryan Boreham authored and GitHub committed 2021-01-18 13:31:58 +00:00
commit 108f0a5c14
1 file changed
+15 -2
+15 -2
View File
@@ -7,6 +7,7 @@ import (
"log" "log"
"os/exec" "os/exec"
"strings" "strings"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@@ -21,6 +22,8 @@ const (
ListSet = Type("list:set") ListSet = Type("list:set")
HashIP = Type("hash:ip") HashIP = Type("hash:ip")
HashNet = Type("hash:net") HashNet = Type("hash:net")
DestroyRetrySleepMs = 100
) )
type Interface interface { type Interface interface {
@@ -153,12 +156,22 @@ func (i *ipset) FlushAll() error {
func (i *ipset) Destroy(ipsetName Name) error { func (i *ipset) Destroy(ipsetName Name) error {
i.removeSetFromUsers(ipsetName) 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 { func (i *ipset) DestroyAll() error {
i.users = make(map[entryKey]map[UID]struct{}) 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 // Fetch a list of all existing sets with a given prefix