From 18cee00df969a8e841f2b8d6c7076449fc1288cf Mon Sep 17 00:00:00 2001 From: Zvonko Kaiser Date: Thu, 7 May 2026 18:34:17 +0000 Subject: [PATCH] build: guard parallel races on build symlink and ~/.docker Parallel make jobs invoke kata-deploy-binaries-in-docker.sh concurrently and collide on two shared paths: ln: Already exists mkdir: /home/$USER/.docker: File exists Skip the symlink creation when the link is already in place. If a parallel job wins the create race in the cold-start window, fall back to re-checking that the link exists so a real ln failure (permission, disk full, etc.) still propagates rather than being silently swallowed. The `~/.docker` mkdir is guarded by a `[[ ! -d ]]` check that two processes can pass simultaneously, after which one bare `mkdir` fails. Switch to `mkdir -p` so the second invocation is a no-op. Assisted-By: Claude Signed-off-by: Zvonko Kaiser --- .../local-build/kata-deploy-binaries-in-docker.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh index fae28b0eb7..fc7fe13d49 100755 --- a/tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh +++ b/tools/packaging/kata-deploy/local-build/kata-deploy-binaries-in-docker.sh @@ -49,8 +49,10 @@ if [[ "${CROSS_BUILD}" == "true" ]]; then [[ -z "${r}" ]] && sudo docker run --privileged --rm tonistiigi/binfmt --install "${TARGET_ARCH}" fi -if [[ "${script_dir}" != "${PWD}" ]]; then - ln -sf "${script_dir}/build" "${PWD}/build" +if [[ "${script_dir}" != "${PWD}" && ! -L "${PWD}/build" ]]; then + # If a parallel job creates the link between the check and our ln, + # accept that and move on; any other failure aborts. + ln -s "${script_dir}/build" "${PWD}/build" 2>/dev/null || [[ -L "${PWD}/build" ]] fi # This is the gid of the "docker" group on host. In case of docker in docker builds @@ -66,7 +68,9 @@ fi remove_dot_docker_dir=false if [[ ! -d "${HOME}/.docker" ]]; then - mkdir "${HOME}"/.docker + # Tolerate the dir being created by a parallel job between the check + # above and this mkdir. + mkdir -p "${HOME}"/.docker remove_dot_docker_dir=true fi