Skip to content

Commit

Permalink
[NPM-3010] avoid potential flakes in TestConntrackExists (#20039)
Browse files Browse the repository at this point in the history
We saw a spike in failures for TestConntrackExists in which
conntrack.Exists() returned false for UDP connections.

My guess is this is because the UDP connections didn't make it all the
way through the kernel before checking if the connection exists.

This PR aims to solve the problem by having PingUDP wait for a response
from the test UDP server to ensure the conntrack entry is initialized.
  • Loading branch information
leeavital authored Oct 11, 2023
1 parent b9a5042 commit 1798c00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/network/testutil/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func PingUDP(tb require.TestingT, ip net.IP, port int) net.Conn {
return nil
}

bs := make([]byte, 10)
n, err := conn.Read(bs)
require.NoError(tb, err)
require.Equal(tb, []byte("pong"), bs[:n])

return conn
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/network/testutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,19 @@ func StartServerUDP(t *testing.T, ip net.IP, port int) io.Closer {
Port: port,
}

l, err := net.ListenUDP(network, addr)
udpConn, err := net.ListenUDP(network, addr)
require.NoError(t, err)
go func() {
close(ch)

for {
bs := make([]byte, 10)
_, err := l.Read(bs)
_, addr, err := udpConn.ReadFrom(bs)
if err != nil {
return
}

_, err = udpConn.WriteTo([]byte("pong"), addr)
if err != nil {
return
}
Expand All @@ -132,5 +137,5 @@ func StartServerUDP(t *testing.T, ip net.IP, port int) io.Closer {
}
}, 3*time.Second, 10*time.Millisecond, "timed out waiting for UDP server to come up")

return l
return udpConn
}

0 comments on commit 1798c00

Please sign in to comment.