{"record":{"id":"ca2551bc162caa38","repo":"juanfont/headscale","slug":"listing-stopped-containers-w","errorCode":null,"errorMessage":"listing stopped containers: %w","messagePattern":"listing stopped containers: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/cleanup.go","lineNumber":145,"sourceCode":"// This is useful for cleaning up leftover containers from previous crashed or interrupted test runs\n// without interfering with currently running concurrent tests.\nfunc cleanupStaleTestContainers(ctx context.Context) error {\n\tcli, err := createDockerClient(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating Docker client: %w\", err)\n\t}\n\tdefer cli.Close()\n\n\t// Only get stopped/exited containers\n\tcontainers, err := cli.ContainerList(ctx, container.ListOptions{\n\t\tAll: true,\n\t\tFilters: filters.NewArgs(\n\t\t\tfilters.Arg(\"status\", \"exited\"),\n\t\t\tfilters.Arg(\"status\", \"dead\"),\n\t\t),\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"listing stopped containers: %w\", err)\n\t}\n\n\tremoved := 0\n\n\tfor _, cont := range containers {\n\t\t// Only remove containers that look like test containers\n\t\tif isTestContainerName(cont.Names) {\n\t\t\tif killAndRemove(ctx, cli, cont) {\n\t\t\t\tremoved++\n\t\t\t}\n\t\t}\n\t}\n\n\tif removed > 0 {\n\t\tfmt.Printf(\"Removed %d stale test containers\\n\", removed)\n\t}\n\n\treturn nil","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/cleanup.go#L127-L163","documentation":"Returned by cleanupStaleTestContainers when ContainerList with status filters (exited, dead) fails. Beyond connectivity/permission causes, this specific call can fail when the daemon rejects the multi-value status filter — e.g. very old Docker engines or proxies (some docker socket proxies whitelist endpoints and filter arguments).","triggerScenarios":"Running pre-test cleanup behind a restricted docker API proxy that blocks or mangles the /containers/json?filters= call; daemon restarting; API version mismatch; permission denial on the socket.","commonSituations":"CI images using tecnativa/docker-socket-proxy or similar with a narrow endpoint whitelist; old Docker versions; transient daemon unavailability; shared daemons with ACLs.","solutions":["Test manually: docker ps -a --filter status=exited --filter status=dead","If using a socket proxy, allow the /containers/json endpoint (and container removal) through it","Retry once the daemon is reachable; check `docker version`","Unpin DOCKER_API_VERSION if set to an incompatible value"],"exampleFix":"# docker-socket-proxy: permit container listing\n-e CONTAINERS=1","handlingStrategy":"validation","validationCode":"# Verify the exact filter combination hi uses\ndocker ps -a --filter status=exited --filter status=dead","typeGuard":null,"tryCatchPattern":"Reproduce the filtered listing manually; proxy/whitelist problems show up immediately there and can be fixed before re-running hi.","preventionTips":["On docker-socket-proxy deployments enable CONTAINERS=1","Upgrade engines older than multi-value status filter support","Check daemon logs when filters inexplicably fail"],"tags":["docker","container-list","filters","pre-test-cleanup"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}