FlushSet is unreliable, occasionally elements remain in the set
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- go
- Domain
- networking
Research direction
The reproducer centers on Conn.FlushSet, Conn.Flush, and Conn.GetSetElements; start by running TestFlushSet on the reported Linux environment and tracing those calls. Determine why the set can retain elements, then add or update a regression test that verifies the set is empty after FlushSet.
Written by the indexing model from the issue text.
Description
I'm running into occasional errors when working with sets / maps. I narrowed this down to the FlushSet function, which sometimes doesn't actually flush the set, i.e. the set sometimes is not empty after FlushSet.
It usually works as expected, but in 5-10% of the cases, the existing elements remain in the set.
I observed this behavior both with v0.3.0, as well as with the current state of the master branch.
Kernel information:
❯ uname -a
Linux linode-sg 5.15.0-131-generic #141-Ubuntu SMP Fri Jan 10 21:18:28 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Here's a minimal example to reproduce the bug. It does the following:
- It creates a table and a set.
- Adds some elements to the set.
- Flushes the set using
FlushSet. - Checks that there are 0 elements remaining.
package loadbalancer
import (
"testing"
"github.com/google/nftables"
"github.com/google/nftables/binaryutil"
"github.com/stretchr/testify/require"
)
func TestFlushSet(t *testing.T) {
conn := &nftables.Conn{}
table := &nftables.Table{
Name: "test_table",
Family: nftables.TableFamilyIPv4,
}
conn.AddTable(table)
t.Cleanup(func() {
conn.DelTable(table)
require.NoError(t, conn.Flush(), "failed to delete table")
})
set := &nftables.Set{
Name: "test_set",
Table: table,
IsMap: false,
KeyType: nftables.TypeInetService, // 2-byte key (e.g., ports)
}
require.NoError(t, conn.AddSet(set, nil), "failed to add set")
elements := []nftables.SetElement{
{Key: binaryutil.BigEndian.PutUint16(80)}, // Port 80
{Key: binaryutil.BigEndian.PutUint16(443)}, // Port 443
{Key: binaryutil.BigEndian.PutUint16(8080)}, // Port 8080
}
require.NoError(t, conn.SetAddElements(set, elements), "failed to add elements")
require.NoError(t, conn.Flush(), "failed to flush added elements")
conn.FlushSet(set)
require.NoError(t, conn.Flush(), "failed to flush the flush")
// check that the set is empty
elems, err := conn.GetSetElements(set)
require.NoError(t, err, "failed to get set elements after flush")
require.Empty(t, elems, "set not empty after flush")
}
- Dominant language
- Go
- Stars
- 1.4k
- Forks
- 187
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/nftables
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Multiple Netlink Decode Paths Can Panic on Malformed or Undersized InputPossibly taken @vulragrag-star claimed this 31 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 68/100
-
New Tag release.Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
automation models
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
QuantumNous/new-api#7930 ·
Maintainers usually reply within 1 day
-
area/gateway kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
vllm-project/aibrix#3226 · 1 comment ·
Maintainers usually reply within 1 day
-
kind/bug kind/flake
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
kubernetes-sigs/kueue#17518 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day