{"record":{"id":"e04c097a4583e799","repo":"GoogleContainerTools/skaffold","slug":"cleaning-up-skaffold-created-network","errorCode":null,"errorMessage":"cleaning up skaffold created network","messagePattern":"cleaning up skaffold created network","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/skaffold/actions/docker/exec_env.go","lineNumber":127,"sourceCode":"func (e ExecEnv) PrepareActions(ctx context.Context, out io.Writer, allbuilds, _ []graph.Artifact, acsNames []string) ([]actions.Action, error) {\n\tif e.shouldCreateNetwork {\n\t\tif err := e.client.NetworkCreate(ctx, e.network, nil); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"creating skaffold network %s: %w\", e.network, err)\n\t\t}\n\t}\n\n\te.logger.Start(ctx, out)\n\n\treturn e.createActions(ctx, out, allbuilds, acsNames)\n}\n\nfunc (e ExecEnv) Cleanup(ctx context.Context, out io.Writer) error {\n\tif !e.shouldCreateNetwork {\n\t\treturn nil\n\t}\n\n\tif err := e.client.NetworkRemove(ctx, e.network); err != nil {\n\t\treturn errors.Wrap(err, \"cleaning up skaffold created network\")\n\t}\n\n\treturn nil\n}\n\nfunc (e ExecEnv) Stop() {\n\te.logger.Stop() // Print the logs of the containers that were not able to print during execution.\n}\n\nfunc (e ExecEnv) createActions(ctx context.Context, out io.Writer, bs []graph.Artifact, acsNames []string) ([]actions.Action, error) {\n\tvar trackedBuilds []graph.Artifact\n\tvar acs []actions.Action\n\tbuiltArtifacts := map[string]graph.Artifact{}\n\n\tfor _, b := range bs {\n\t\tbuiltArtifacts[b.ImageName] = b\n\t}\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/actions/docker/exec_env.go#L109-L145","documentation":"ExecEnv.Cleanup in Skaffold's docker action executor removes the Docker network that was created for the test/action run. If client.NetworkRemove fails, the error is wrapped as \"cleaning up skaffold created network\". This is a teardown-stage failure: the run itself already happened, but resources were not reclaimed.","triggerScenarios":"Calling Cleanup when shouldCreateNetwork is true and NetworkRemove errors: network already removed by another process or concurrent cleanup, network still in use by attached containers, or the Docker daemon is unreachable/restarted.","commonSituations":"Containers from the run are still running and attached, so Docker refuses to remove the network (\"network has active endpoints\"); parallel skaffold runs deleting each other's networks; docker daemon restart mid-run; hitting a context cancellation/timeout during teardown.","solutions":["Ensure all containers attached to the network are stopped before Cleanup (Stop tasks first, then Cleanup).","Manually remove the leftover network: `docker network rm <network>` after checking `docker network ls`.","Check the unwrapped docker error; if 'network has active endpoints', list endpoints with `docker network inspect <network>` and stop them.","If the daemon restarted, the network may be gone already — treat a not-found error as success in the caller.","Avoid concurrent runs sharing the same network name; use unique per-run network names."],"exampleFix":"// before\nif err := env.Cleanup(ctx, out); err != nil { return err }\n// after\nif err := env.Cleanup(ctx, out); err != nil {\n    log.Printf(\"warning: network cleanup failed (run may still succeed): %v\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go\nif err := env.Cleanup(ctx, out); err != nil {\n    // non-fatal teardown failure: log and continue\n    log.Printf(\"warning: %v\", err)\n}\n// manual fallback: docker network rm <network>","preventionTips":["Stop all run containers before Cleanup so the network has no active endpoints.","Use unique network names per run to avoid cross-run deletion.","Treat not-found network errors as successful cleanup."],"tags":["docker","networking","cleanup","resource-leak"],"backgroundTag":"docker-network-remove-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}