Skip to content

Commit

Permalink
Merge pull request #3851 from NeonSludge/fix-ipset-destroy
Browse files Browse the repository at this point in the history
Pause and retry ipset deletion if it fails the first time
  • Loading branch information
bboreham committed Jan 18, 2021
2 parents b04217d + cb2e56f commit 108f0a5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions net/ipset/ipset.go
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

0 comments on commit 108f0a5

Please sign in to comment.