diff --git a/packages/server/src/utils/docker/utils.ts b/packages/server/src/utils/docker/utils.ts index 09fe877cd..42fb252f9 100644 --- a/packages/server/src/utils/docker/utils.ts +++ b/packages/server/src/utils/docker/utils.ts @@ -153,19 +153,27 @@ export const getContainerByName = (name: string): Promise => { */ export const dockerSafeExec = (exec: string) => ` CHECK_INTERVAL=10 +MAX_WAIT=300 +WAITED=0 echo "Preparing for execution..." while true; do - PROCESSES=$(ps aux | grep -E "^.*docker [A-Za-z]" | grep -v grep) + PROCESSES=$(ps -eo args | awk '$1 ~ /(^|\\/)docker$/') if [ -z "$PROCESSES" ]; then echo "Docker is idle. Starting execution..." break - else - echo "Docker is busy. Will check again in $CHECK_INTERVAL seconds..." - sleep $CHECK_INTERVAL fi + + if [ "$WAITED" -ge "$MAX_WAIT" ]; then + echo "Docker still busy after \${MAX_WAIT}s, proceeding anyway." >&2 + break + fi + + echo "Docker is busy. Will check again in $CHECK_INTERVAL seconds..." + sleep $CHECK_INTERVAL + WAITED=$((WAITED + CHECK_INTERVAL)) done ${exec} @@ -323,7 +331,12 @@ export const cleanupAll = async (serverId?: string) => { } else { await execAsync(dockerSafeExec(command)); } - } catch {} + } catch (error) { + console.error( + `Docker cleanup: "${key}" failed${serverId ? ` on server ${serverId}` : ""}`, + error, + ); + } } };