From 1ca608ea9921c63a301f79dffff2fe13c187f97e Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 9 Feb 2024 14:27:21 +0100 Subject: [PATCH] fix "podman run port forward range" flake For some reason this starting to flake f38. I don't think the issue in podman rather the test start nc -l in the background so it may not yet have bound the port in the container when we try to connect. To fix this simply add some retry logic to nc. While at it also add pasta to this test and make it use defer-assertion-failures to run all loop iterations before reporting the errors. Fixes #21561 (hopefully) Signed-off-by: Paul Holzinger --- test/system/500-networking.bats | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats index bba009da2c..ffb71993c7 100644 --- a/test/system/500-networking.bats +++ b/test/system/500-networking.bats @@ -716,7 +716,16 @@ nameserver 8.8.8.8" "nameserver order is correct" } @test "podman run port forward range" { - for netmode in bridge slirp4netns:port_handler=slirp4netns slirp4netns:port_handler=rootlesskit; do + # we run a long loop of tests lets run all combinations before bailing out + defer-assertion-failures + + # pasta only works rootless + local pasta= + if is_rootless; then + pasta=pasta + fi + + for netmode in bridge slirp4netns:port_handler=slirp4netns slirp4netns:port_handler=rootlesskit $pasta; do local range=$(random_free_port_range 3) # die() inside $(...) does not actually stop us. assert "$range" != "" "Could not find free port range" @@ -729,10 +738,22 @@ nameserver 8.8.8.8" "nameserver order is correct" cid="$output" for port in $(seq $port $end_port); do run_podman exec -d $cid nc -l -p $port -e /bin/cat - # -w 1 adds a 1 second timeout. For some reason, ubuntu's ncat - # doesn't close the connection on EOF, and other options to - # change this are not portable across distros. -w seems to work. - run nc -w 1 127.0.0.1 $port <<<$random + + # we have to rety ncat as it can flake as we exec in the background so nc -l + # might not have bound the port yet, retry seems simpler than checking if the + # port is bound in the container, https://github.com/containers/podman/issues/21561. + retries=5 + while [[ $retries -gt 0 ]]; do + # -w 1 adds a 1 second timeout. For some reason, ubuntu's ncat + # doesn't close the connection on EOF, and other options to + # change this are not portable across distros. -w seems to work. + run nc -w 1 127.0.0.1 $port <<<$random + if [[ $status -eq 0 ]]; then + break + fi + sleep 0.5 + retries=$((retries -1)) + done is "$output" "$random" "ncat got data back (netmode=$netmode port=$port)" done