{"record":{"id":"483656b735ce35fb","repo":"GoogleContainerTools/skaffold","slug":"cannot-close-temp-file-w","errorCode":null,"errorMessage":"cannot close temp file: %w","messagePattern":"cannot close temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/helm/util.go","lineNumber":48,"sourceCode":"type buildOutputs struct {\n\tBuilds []graph.Artifact `json:\"builds\"`\n}\n\nfunc writeBuildArtifacts(builds []graph.Artifact) (string, func(), error) {\n\tbuildOutput, err := json.Marshal(buildOutputs{builds})\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot marshal build artifacts: %w\", err)\n\t}\n\n\tf, err := os.CreateTemp(\"\", \"builds*.yaml\")\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot create temp file: %w\", err)\n\t}\n\tif _, err := f.Write(buildOutput); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot write to temp file: %w\", err)\n\t}\n\tif err := f.Close(); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot close temp file: %w\", err)\n\t}\n\treturn f.Name(), func() { os.Remove(f.Name()) }, nil\n}\n\n// SanitizeFilePath is used to sanitize filepaths that are provided to the `setFiles` flag\n// helm `setFiles` doesn't work with the unescaped filepath separator (\\) for Windows or if there are unescaped tabs and spaces in the directory names.\n// So we escape all odd count occurrences of `\\` for Windows, and wrap the entire string in quotes if it has spaces.\n// This is very specific to the way helm handles its flags.\n// See https://github.com/helm/helm/blob/d55c53df4e394fb62b0514a09c57bce235dd7877/pkg/cli/values/options.\n// Otherwise the windows `syscall` package implements its own sanitizing for command args that's used by `exec.Cmd`.\n// See https://github.com/golang/go/blob/6951da56b0ae2cd4250fc1b0350d090aed633ac1/src/syscall/exec_windows.go#L27\nfunc SanitizeFilePath(s string, isWindowsOS bool) string {\n\tif len(s) == 0 {\n\t\treturn `\"\"`\n\t}\n\tneedsQuotes := false\n\tfor i := 0; i < len(s); i++ {\n\t\tif s[i] == ' ' || s[i] == '\\t' {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/helm/util.go#L30-L66","documentation":"After writing the JSON build artifacts, writeBuildArtifacts closes the temp file; failure to close is reported with this error and aborts post-renderer setup. A close failure means buffered data may not be durably flushed to disk, so the artifact file is considered unreliable.","triggerScenarios":"f.Close() returns an error — typically ENOSPC surfaced at flush time (data written earlier sits in the page cache), or an I/O error on the storage backing the temp dir.","commonSituations":"Disk filling up such that the write only fails at close/flush; flaky network storage behind TMPDIR; corrupted filesystem in a long-running CI runner.","solutions":["Check disk space on the temp filesystem; ENOSPC at close is common — free space and retry","Check filesystem health (dmesg, fsck if applicable)","Set TMPDIR to a local, healthy disk instead of network storage","Rerun the deploy; transient storage errors usually clear on retry"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"TD=\"${TMPDIR:-/tmp}\"; df --output=avail \"$TD\" | awk 'NR==2{exit ($1<104857600)?1:0}' || { echo \"free disk space before deploying\"; exit 1; }","typeGuard":null,"tryCatchPattern":"err := deploy(); if err != nil && strings.Contains(err.Error(), \"cannot close temp file\") {\n\t// often transient ENOSPC surfaced at flush; free space and retry once\n\tif retriable(err) { err = deploy() }\n}","preventionTips":["Free disk space before deploys; ENOSPC often surfaces at close","Use local disks (not NFS) for TMPDIR","Rerun once after transient storage errors","Check filesystem health if failures repeat"],"tags":["temp-file","io","close","helm"],"backgroundTag":"temp-file-write-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"}