From 89867681515211cf36fb035291db4bfb20c220ab Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Thu, 29 Oct 2026 16:29:08 +0100 Subject: neutron: Fix wrapper container name race Neutron can respawn a process immediately after terminating the previous one, before the container runtime has removed the old --rm container, causing "container name already in use" errors. Wait for the name to be released and remove any leftover container before starting a new one. Closes-Bug: #2172507 Change-Id: I4df8794f9a0daf587882fdcae042e04b7442ac26 Signed-off-by: Michal Nasiadka --- kolla/docker/neutron/neutron-base/dnsmasq | 16 ++++++++++++---- kolla/docker/neutron/neutron-base/haproxy | 16 ++++++++++++---- kolla/docker/neutron/neutron-base/keepalived | 16 ++++++++++++---- kolla/docker/neutron/neutron-base/radvd | 15 ++++++++++++--- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/kolla/docker/neutron/neutron-base/dnsmasq b/kolla/docker/neutron/neutron-base/dnsmasq index 44b73f0b2..9138e7f66 100644 --- a/kolla/docker/neutron/neutron-base/dnsmasq +++ b/kolla/docker/neutron/neutron-base/dnsmasq @@ -24,10 +24,18 @@ else exit 1 fi -LIST=$($CLI ps -a --filter name=${SERVICE}_dnsmasq_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}') - -# If the NAME is already taken by a container, give it an unique name -printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)" +# NOTE: Neutron may respawn dnsmasq right after killing the previous +# instance, before the container runtime has finished tearing down the +# old --rm container, so its name can still be taken. Wait for the name +# to be released and remove the old container if it is still there. +for _ in $(seq 1 10); do + $CLI container inspect "${NAME}" >/dev/null 2>&1 || break + sleep 0.5 +done +if $CLI container inspect "${NAME}" >/dev/null 2>&1; then + echo "Removing leftover child container ${NAME}" + $CLI rm -f "${NAME}" >/dev/null +fi echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}" $CLI run --rm --detach \ diff --git a/kolla/docker/neutron/neutron-base/haproxy b/kolla/docker/neutron/neutron-base/haproxy index 43b9ef9d2..524b7b7dd 100644 --- a/kolla/docker/neutron/neutron-base/haproxy +++ b/kolla/docker/neutron/neutron-base/haproxy @@ -24,10 +24,18 @@ else exit 1 fi -LIST=$($CLI ps -a --filter name=${KOLLA_NAME}_haproxy_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}') - -# If the NAME is already taken by a container, give it an unique name -printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)" +# NOTE: Neutron may respawn haproxy right after killing the previous +# instance, before the container runtime has finished tearing down the +# old --rm container, so its name can still be taken. Wait for the name +# to be released and remove the old container if it is still there. +for _ in $(seq 1 10); do + $CLI container inspect "${NAME}" >/dev/null 2>&1 || break + sleep 0.5 +done +if $CLI container inspect "${NAME}" >/dev/null 2>&1; then + echo "Removing leftover child container ${NAME}" + $CLI rm -f "${NAME}" >/dev/null +fi echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}" $CLI run --rm --detach \ diff --git a/kolla/docker/neutron/neutron-base/keepalived b/kolla/docker/neutron/neutron-base/keepalived index 6bb2b4d3d..1ad95d32e 100644 --- a/kolla/docker/neutron/neutron-base/keepalived +++ b/kolla/docker/neutron/neutron-base/keepalived @@ -24,10 +24,18 @@ else exit 1 fi -LIST=$($CLI ps -a --filter name=${KOLLA_SERVICE}_keepalived_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}') - -# If the NAME is already taken by a container, give it an unique name -printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)" +# NOTE: Neutron may respawn keepalived right after killing the previous +# instance, before the container runtime has finished tearing down the +# old --rm container, so its name can still be taken. Wait for the name +# to be released and remove the old container if it is still there. +for _ in $(seq 1 10); do + $CLI container inspect "${NAME}" >/dev/null 2>&1 || break + sleep 0.5 +done +if $CLI container inspect "${NAME}" >/dev/null 2>&1; then + echo "Removing leftover child container ${NAME}" + $CLI rm -f "${NAME}" >/dev/null +fi echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}" $CLI run --rm --detach \ diff --git a/kolla/docker/neutron/neutron-base/radvd b/kolla/docker/neutron/neutron-base/radvd index 3f5dd1cfa..dac159130 100644 --- a/kolla/docker/neutron/neutron-base/radvd +++ b/kolla/docker/neutron/neutron-base/radvd @@ -22,9 +22,18 @@ else exit 1 fi -LIST=$($CLI ps -a --filter name=${KOLLA_NAME}_radvd_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}') -# If the NAME is already taken by a container, give it an unique name -printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)" +# NOTE: Neutron may respawn radvd right after killing the previous +# instance, before the container runtime has finished tearing down the +# old --rm container, so its name can still be taken. Wait for the name +# to be released and remove the old container if it is still there. +for _ in $(seq 1 10); do + $CLI container inspect "${NAME}" >/dev/null 2>&1 || break + sleep 0.5 +done +if $CLI container inspect "${NAME}" >/dev/null 2>&1; then + echo "Removing leftover child container ${NAME}" + $CLI rm -f "${NAME}" >/dev/null +fi echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}" $CLI run --rm --detach \ -- cgit v1.2.3