Skip to content

Commit

Permalink
Fixing iptables-restore flakiness (#27011)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielLavie committed Jun 24, 2024
1 parent 16ca2d9 commit eb1b1dc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/network/testutil/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,20 @@ func IptablesSave(tb testing.TB) []byte {

// IptablesRestore restores iptables state from a file
func IptablesRestore(tb testing.TB, state []byte) {
cmd := exec.Command("iptables-restore", "--counters")
cmd.Stdin = bytes.NewReader(state)
assert.NoError(tb, cmd.Run())
var restoreErr error
// The attempt mechanism is necessary because we noticed that iptables-restore fails with error code 4 when it can't acquire the lock.
// We can't rely on the --wait flag as it's not available on older versions of iptables.
for attempt := 0; attempt < 3; attempt++ {
cmd := exec.Command("iptables-restore", "--counters")
cmd.Stdin = bytes.NewReader(state)
restoreErr = cmd.Run()

// If no error occurs, return early.
if restoreErr == nil {
return
}
}
assert.NoError(tb, restoreErr)
}

// Ip6tablesSave saves the current iptables state to a file
Expand Down

0 comments on commit eb1b1dc

Please sign in to comment.