From bdd4ff0bacbf73de61c9c5d232c6b3a330c55cc3 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 11 Nov 2026 18:34:50 +0100 Subject: [PATCH 1/5] Fix socat bridge creation in docker-init.sh.tmpl Updated socat bridge creation to ensure proper socket connection order and background execution. --- features/src/docker-out/docker-init.sh.tmpl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/features/src/docker-out/docker-init.sh.tmpl b/features/src/docker-out/docker-init.sh.tmpl index b42e33b..3b6756a 100755 --- a/features/src/docker-out/docker-init.sh.tmpl +++ b/features/src/docker-out/docker-init.sh.tmpl @@ -75,8 +75,12 @@ else exit 1 fi fi - # Create the socat bridge - sudoIf socat UNIX-CONNECT:${SOURCE_SOCKET} UNIX-LISTEN:${TARGET_SOCKET},fork,user=${USERNAME},group=docker,mode=660 + # Create the socat bridge. The listener must be the first address: socat opens the first + # address once, so with UNIX-CONNECT first every forked client shared one daemon connection. + # Backgrounded so the script reaches `exec "$@"` below instead of blocking on socat. + sudoIf socat UNIX-LISTEN:${TARGET_SOCKET},fork,user=${USERNAME},group=docker,mode=660 UNIX-CONNECT:${SOURCE_SOCKET} & + # Wait for the listener so a command run right after start does not race it. + for _ in $(seq 1 50); do [ -S "${TARGET_SOCKET}" ] && break; sleep 0.1; done fi fi From f34dac2c2d3379912297a39184c4bf83e93c3827 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 11 Nov 2026 18:40:48 +0100 Subject: [PATCH 2/5] Implement error check for Docker socket bridge Add error handling for Docker socket readiness. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- features/src/docker-out/docker-init.sh.tmpl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/src/docker-out/docker-init.sh.tmpl b/features/src/docker-out/docker-init.sh.tmpl index 3b6756a..161e409 100755 --- a/features/src/docker-out/docker-init.sh.tmpl +++ b/features/src/docker-out/docker-init.sh.tmpl @@ -81,6 +81,10 @@ else sudoIf socat UNIX-LISTEN:${TARGET_SOCKET},fork,user=${USERNAME},group=docker,mode=660 UNIX-CONNECT:${SOURCE_SOCKET} & # Wait for the listener so a command run right after start does not race it. for _ in $(seq 1 50); do [ -S "${TARGET_SOCKET}" ] && break; sleep 0.1; done + if [ ! -S "${TARGET_SOCKET}" ]; then + echo "Error: Docker socket bridge did not become ready at ${TARGET_SOCKET}." >&2 + exit 1 + fi fi fi From 660e7f71f711a9d41ce468dbf4d69fdf6ff8218d Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 11 Nov 2026 19:32:43 +0100 Subject: [PATCH 3/5] Improve Docker socket bridge readiness check Replace socket readiness check with connection probe using socat. --- features/src/docker-out/docker-init.sh.tmpl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/features/src/docker-out/docker-init.sh.tmpl b/features/src/docker-out/docker-init.sh.tmpl index 161e409..d8343c3 100755 --- a/features/src/docker-out/docker-init.sh.tmpl +++ b/features/src/docker-out/docker-init.sh.tmpl @@ -79,10 +79,16 @@ else # address once, so with UNIX-CONNECT first every forked client shared one daemon connection. # Backgrounded so the script reaches `exec "$@"` below instead of blocking on socat. sudoIf socat UNIX-LISTEN:${TARGET_SOCKET},fork,user=${USERNAME},group=docker,mode=660 UNIX-CONNECT:${SOURCE_SOCKET} & - # Wait for the listener so a command run right after start does not race it. - for _ in $(seq 1 50); do [ -S "${TARGET_SOCKET}" ] && break; sleep 0.1; done - if [ ! -S "${TARGET_SOCKET}" ]; then - echo "Error: Docker socket bridge did not become ready at ${TARGET_SOCKET}." >&2 + # Probe by connecting: the path exists from bind(), before listen(), so [ -S ] passes too early. + # sudoIf because this process predates the usermod above and lacks the docker group. + BRIDGE_READY=false + for _ in $(seq 1 50); do + if sudoIf socat -u /dev/null UNIX-CONNECT:"${TARGET_SOCKET}" 2>/dev/null; then BRIDGE_READY=true; break; fi + sleep 0.1 + done + # set -e cannot see a backgrounded socat fail, so check the result explicitly. + if [ "${BRIDGE_READY}" != true ]; then + echo "Error: socat bridge at ${TARGET_SOCKET} accepted no connection within 5s." >&2 exit 1 fi fi From e659f04de54de3e20368e2c8fff300d12c94c5a5 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 11 Nov 2026 21:06:08 +0100 Subject: [PATCH 4/5] Update docker-init.sh.tmpl From 7cc51b714f67189df42ab600e008853dff553c51 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 11 Nov 2026 21:08:53 +0100 Subject: [PATCH 5/5] Improve error handling for socket path conflict Added error handling for SOURCE_SOCKET and TARGET_SOCKET conflict in docker-init.sh template. --- features/src/docker-out/docker-init.sh.tmpl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/features/src/docker-out/docker-init.sh.tmpl b/features/src/docker-out/docker-init.sh.tmpl index d8343c3..2eed0d1 100755 --- a/features/src/docker-out/docker-init.sh.tmpl +++ b/features/src/docker-out/docker-init.sh.tmpl @@ -58,6 +58,12 @@ else else # Use socat echo "Using socat to bridge socket from GID $SOCKET_GID to docker GID $DOCKER_GID." + # A bridge onto its own source would delete it, then the listener would connect to itself. + # A string compare suffices: two spellings of one file already failed at the ln -s above. + if [ "${SOURCE_SOCKET}" = "${TARGET_SOCKET}" ]; then + echo "Error: SOURCE_SOCKET and TARGET_SOCKET are both ${SOURCE_SOCKET}, but its GID ${SOCKET_GID} belongs to group ${EXISTING_GROUP}, not docker. Mount the host socket at a different path than TARGET_SOCKET." >&2 + exit 1 + fi sudoIf rm -rf ${TARGET_SOCKET} # Check if socat is installed if command -v socat > /dev/null 2>&1; then