{"record":{"id":"0b8342056d322d69","repo":"juanfont/headscale","slug":"pruning-networks-w","errorCode":null,"errorMessage":"pruning networks: %w","messagePattern":"pruning networks: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/cleanup.go","lineNumber":29,"sourceCode":"\n\t\"github.com/cenkalti/backoff/v5\"\n\t\"github.com/docker/docker/api/types/container\"\n\t\"github.com/docker/docker/api/types/filters\"\n\t\"github.com/docker/docker/api/types/image\"\n\t\"github.com/docker/docker/client\"\n\t\"github.com/docker/docker/errdefs\"\n)\n\n// cleanupBeforeTest performs cleanup operations before running tests.\n// Only removes stale (stopped/exited) test containers to avoid interfering with concurrent test runs.\nfunc cleanupBeforeTest(ctx context.Context) error {\n\terr := cleanupStaleTestContainers(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cleaning stale test containers: %w\", err)\n\t}\n\n\tif err := pruneDockerNetworks(ctx); err != nil { //nolint:noinlineerr\n\t\treturn fmt.Errorf(\"pruning networks: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// cleanupAfterTest removes the test container and all associated integration test containers for the run.\nfunc cleanupAfterTest(ctx context.Context, cli *client.Client, containerID, runID string) error {\n\t// Remove the main test container\n\terr := cli.ContainerRemove(ctx, containerID, container.RemoveOptions{\n\t\tForce: true,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"removing test container: %w\", err)\n\t}\n\n\t// Clean up integration test containers for this run only\n\tif runID != \"\" {\n\t\terr := killTestContainersByRunID(ctx, runID)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/cleanup.go#L11-L47","documentation":"Returned by cleanupBeforeTest when pruneDockerNetworks fails. pruneDockerNetworks creates a Docker client and calls cli.NetworksPrune, which asks the daemon to delete unused networks. Failures come from daemon connectivity/permission problems or from the daemon rejecting the prune call itself (e.g. networks still referenced by containers on some setups).","triggerScenarios":"Pre-test cleanup running when the Docker daemon is unreachable or the user cannot access it; NetworksPrune returning an API error such as a conflict because a custom network is in use by another container outside the test's control.","commonSituations":"Shared CI machines with other containers attached to custom networks; remote DOCKER_HOST where pruning is disallowed; transient daemon restarts mid-cleanup; user not in the docker group.","solutions":["Check the wrapped message after 'pruning networks:' to identify the API-level cause","Verify `docker network prune` works manually with the same user and DOCKER_HOST","Stop containers that hold references to custom networks, or accept that prune is best-effort and fix the connectivity issue","Ensure DOCKER_HOST/DOCKER_CONTEXT point to the intended daemon"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Treat prune failures as best-effort: log and continue if the underlying test goal matters more; retry once after verifying `docker network prune` succeeds manually.","preventionTips":["Periodically prune networks manually on shared CI machines so hi's prune has nothing conflicting to do","Verify daemon health before test runs","Avoid attaching unrelated containers to custom networks on machines running integration tests"],"tags":["docker","networks","cleanup","integration-tests"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}