Skip to content

Commit c24a570

Browse files
committed
fix: docker cleanup hangs silently on false-positive busy-wait match
dockerSafeExec's busy-wait matched any process with "docker <letter>" anywhere in its argv (e.g. Grafana's --packaging=docker cfg:...), causing the wait loop to spin forever. Anchor the match to the actual docker binary (argv[0]) instead, and add a MAX_WAIT ceiling so a genuinely stuck docker process can't hang cleanup indefinitely either. Also log failures in cleanupAll's catch instead of swallowing them, since the scheduled cleanup path only goes through this function. Fixes #5044
1 parent 3fbd67f commit c24a570

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

  • packages/server/src/utils/docker

‎packages/server/src/utils/docker/utils.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,27 @@ export const getContainerByName = (name: string): Promise<ContainerInfo> => {
153153
*/
154154
export const dockerSafeExec = (exec: string) => `
155155
CHECK_INTERVAL=10
156+
MAX_WAIT=300
157+
WAITED=0
156158
157159
echo "Preparing for execution..."
158160
159161
while true; do
160-
PROCESSES=$(ps aux | grep -E "^.*docker [A-Za-z]" | grep -v grep)
162+
PROCESSES=$(ps -eo args | awk '$1 ~ /(^|\\/)docker$/')
161163
162164
if [ -z "$PROCESSES" ]; then
163165
echo "Docker is idle. Starting execution..."
164166
break
165-
else
166-
echo "Docker is busy. Will check again in $CHECK_INTERVAL seconds..."
167-
sleep $CHECK_INTERVAL
168167
fi
168+
169+
if [ "$WAITED" -ge "$MAX_WAIT" ]; then
170+
echo "Docker still busy after \${MAX_WAIT}s, proceeding anyway." >&2
171+
break
172+
fi
173+
174+
echo "Docker is busy. Will check again in $CHECK_INTERVAL seconds..."
175+
sleep $CHECK_INTERVAL
176+
WAITED=$((WAITED + CHECK_INTERVAL))
169177
done
170178
171179
${exec}
@@ -323,7 +331,12 @@ export const cleanupAll = async (serverId?: string) => {
323331
} else {
324332
await execAsync(dockerSafeExec(command));
325333
}
326-
} catch {}
334+
} catch (error) {
335+
console.error(
336+
`Docker cleanup: "${key}" failed${serverId ? ` on server ${serverId}` : ""}`,
337+
error,
338+
);
339+
}
327340
}
328341
};
329342

0 commit comments

Comments
 (0)