{"record":{"id":"e17e51bafa696274","repo":"juanfont/headscale","slug":"listing-containers-for-run-s-w","errorCode":null,"errorMessage":"listing containers for run %s: %w","messagePattern":"listing containers for run (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/hi/cleanup.go","lineNumber":108,"sourceCode":"// killTestContainersByRunID terminates and removes all test containers for a specific run ID.\n// This function filters containers by the hi.run-id label to only affect containers\n// belonging to the specified test run, leaving other concurrent test runs untouched.\nfunc killTestContainersByRunID(ctx context.Context, runID string) 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// Filter containers by hi.run-id label\n\tcontainers, err := cli.ContainerList(ctx, container.ListOptions{\n\t\tAll: true,\n\t\tFilters: filters.NewArgs(\n\t\t\tfilters.Arg(\"label\", \"hi.run-id=\"+runID),\n\t\t),\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"listing containers for run %s: %w\", runID, err)\n\t}\n\n\tremoved := 0\n\n\tfor _, cont := range containers {\n\t\tif killAndRemove(ctx, cli, cont) {\n\t\t\tremoved++\n\t\t}\n\t}\n\n\tif removed > 0 {\n\t\tfmt.Printf(\"Removed %d containers for run ID %s\\n\", removed, runID)\n\t}\n\n\treturn nil\n}\n\n// cleanupStaleTestContainers removes stopped/exited test containers without affecting running tests.","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/cleanup.go#L90-L126","documentation":"Returned by killTestContainersByRunID when the label-filtered ContainerList (label hi.run-id=<runID>) fails. This is a Docker API-level failure: connectivity loss, permission denial, or (on ancient engines) poor handling of label filters. Distinct from removal failures — the run's containers were not even enumerated.","triggerScenarios":"Daemon restarting at teardown; API version mismatch rejecting the filter; permission denied; network interruption to a remote daemon while listing.","commonSituations":"Concurrent CI jobs stressing the daemon; DOCKER_API_VERSION pinned incorrectly; remote docker contexts over unstable links; daemon crash-looping due to disk pressure.","solutions":["Run the equivalent query manually: docker ps -a --filter label=hi.run-id=<runID>","Retry the operation once the daemon is stable","Unset DOCKER_API_VERSION if pinned; upgrade ancient Docker engines","Free disk/inodes if the daemon is crash-looping (check journalctl -u docker)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Equivalent check for the exact filter hi uses\ndocker ps -a --filter \"label=hi.run-id=<runID>\"","typeGuard":null,"tryCatchPattern":"Reproduce the list manually with the label filter; if that works, retry the hi command; if not, fix daemon/proxy configuration.","preventionTips":["Whitelist /containers/json (with filters) on docker socket proxies","Keep label metadata intact on test containers","Retry once after daemon connectivity is confirmed"],"tags":["docker","container-list","labels","integration-tests"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}