Pause and retry ipset deletion if it fails the first time

This commit is contained in:
Kirill Buev committed 2020-08-24 16:23:52 +03:00
1 parent 30ce219794
commit cb2e56fc44
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