Skip to content

Commit 11c295b

Browse files
alessandrocarminatiroxanan1996
authored andcommitted
selftests/bpf: Prevent client connect before server bind in test_tc_tunnel.sh
BugLink: https://bugs.launchpad.net/bugs/2073765 [ Upstream commit f803bcf ] In some systems, the netcat server can incur in delay to start listening. When this happens, the test can randomly fail in various points. This is an example error message: # ip gre none gso # encap 192.168.1.1 to 192.168.1.2, type gre, mac none len 2000 # test basic connectivity # Ncat: Connection refused. The issue stems from a race condition between the netcat client and server. The test author had addressed this problem by implementing a sleep, which I have removed in this patch. This patch introduces a function capable of sleeping for up to two seconds. However, it can terminate the waiting period early if the port is reported to be listening. Signed-off-by: Alessandro Carminati (Red Hat) <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Portia Stephens <[email protected]> Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent 3093a6a commit 11c295b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/testing/selftests/bpf/test_tc_tunnel.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ cleanup() {
7171
server_listen() {
7272
ip netns exec "${ns2}" nc "${netcat_opt}" -l "${port}" > "${outfile}" &
7373
server_pid=$!
74-
sleep 0.2
7574
}
7675

7776
client_connect() {
@@ -92,6 +91,16 @@ verify_data() {
9291
fi
9392
}
9493

94+
wait_for_port() {
95+
for i in $(seq 20); do
96+
if ip netns exec "${ns2}" ss ${2:--4}OHntl | grep -q "$1"; then
97+
return 0
98+
fi
99+
sleep 0.1
100+
done
101+
return 1
102+
}
103+
95104
set -e
96105

97106
# no arguments: automated test, run all
@@ -189,6 +198,7 @@ setup
189198
# basic communication works
190199
echo "test basic connectivity"
191200
server_listen
201+
wait_for_port ${port} ${netcat_opt}
192202
client_connect
193203
verify_data
194204

@@ -200,6 +210,7 @@ ip netns exec "${ns1}" tc filter add dev veth1 egress \
200210
section "encap_${tuntype}_${mac}"
201211
echo "test bpf encap without decap (expect failure)"
202212
server_listen
213+
wait_for_port ${port} ${netcat_opt}
203214
! client_connect
204215

205216
if [[ "$tuntype" =~ "udp" ]]; then

0 commit comments

Comments
 (0)