Skip to content

Commit 7d15bc2

Browse files
committed
fix userns + restart policy with slirp4netns
Currently we deadlock in the slirp4netns setup code as we try to configure an non exissting netns. The problem happens because we tear down the netns in the userns case correctly since commit bbd6281 but that introduces this slirp4netns problem. The code does a proper new network setup later so we should only use the short cut when not in a userns. Fixes #21477 Signed-off-by: Paul Holzinger <[email protected]>
1 parent a2f0a44 commit 7d15bc2

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

libpod/container_internal.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,13 @@ func (c *Container) handleRestartPolicy(ctx context.Context) (_ bool, retErr err
306306
return false, err
307307
}
308308

309-
// set up slirp4netns again because slirp4netns will die when conmon exits
310-
if err := c.setupRootlessNetwork(); err != nil {
311-
return false, err
309+
// only do this if the container is not in a userns, if we are the cleanupNetwork()
310+
// was called above and a proper network setup is needed which is part of the init() below.
311+
if !c.config.PostConfigureNetNS {
312+
// set up slirp4netns again because slirp4netns will die when conmon exits
313+
if err := c.setupRootlessNetwork(); err != nil {
314+
return false, err
315+
}
312316
}
313317

314318
if c.state.State == define.ContainerStateStopped {

test/system/500-networking.bats

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -874,16 +874,14 @@ EOF
874874
# Test for https://github.com/containers/podman/issues/18615
875875
@test "podman network cleanup --userns + --restart" {
876876
skip_if_cgroupsv1 "run --uidmap fails on cgroups v1 (issue 15025, wontfix)"
877-
userns="--userns=keep-id"
878-
if ! is_rootless; then
879-
userns="--uidmap=0:1111111:65536 --gidmap=0:1111111:65536"
880-
fi
881877

882878
local net1=a-$(random_string 10)
883879
# use /29 subnet to limit available ip space, a 29 gives 5 usable addresses (6 - 1 for the gw)
884880
local subnet="$(random_rfc1918_subnet).0/29"
885881
run_podman network create --subnet $subnet $net1
886-
local cname=con-$(random_string 10)
882+
local cname=con1-$(random_string 10)
883+
local cname2=con2-$(random_string 10)
884+
local cname3=
887885

888886
local netns_count=
889887
if ! is_rootless; then
@@ -896,18 +894,31 @@ EOF
896894

897895
# Previously this would fail as the container would run out of ips after 5 restarts.
898896
run_podman inspect --format "{{.RestartCount}}" $cname
899-
assert "$output" == "6" "RestartCount for failing container"
897+
assert "$output" == "6" "RestartCount for failing container with bridge network"
900898

901899
# Now make sure we can still run a container with free ips.
902900
run_podman run --rm --network $net1 $IMAGE true
903901

904-
if ! is_rootless; then
902+
# And now because of all the fun we have to check the same with slirp4netns and pasta because
903+
# that uses slighlty different code paths. Note this would dealock before the fix.
904+
# https://github.com/containers/podman/issues/21477
905+
run_podman 1 run --name $cname2 --network slirp4netns --restart on-failure:2 --userns keep-id $IMAGE false
906+
run_podman inspect --format "{{.RestartCount}}" $cname2
907+
assert "$output" == "2" "RestartCount for failing container with slirp4netns"
908+
909+
if is_rootless; then
910+
# pasta can only run rootless
911+
cname3=con3-$(random_string 10)
912+
run_podman 1 run --name $cname3 --network pasta --restart on-failure:2 --userns keep-id $IMAGE false
913+
run_podman inspect --format "{{.RestartCount}}" $cname3
914+
assert "$output" == "2" "RestartCount for failing container with pasta"
915+
else
905916
# This is racy if other programs modify /run/netns while the test is running.
906917
# However I think the risk is minimal and I think checking for this is important.
907918
assert "$(ls /run/netns | wc -l)" == "$netns_count" "/run/netns has no leaked netns files"
908919
fi
909920

910-
run_podman rm -f -t0 $cname
921+
run_podman rm -f -t0 $cname $cname2 $cname3
911922
run_podman network rm $net1
912923
}
913924

0 commit comments

Comments
 (0)