GoogleContainerTools/skaffold · error
cannot close temp file: %w
Error message
cannot close temp file: %w
What it means
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.
Source
Thrown at pkg/skaffold/helm/util.go:48
type buildOutputs struct {
Builds []graph.Artifact `json:"builds"`
}
func writeBuildArtifacts(builds []graph.Artifact) (string, func(), error) {
buildOutput, err := json.Marshal(buildOutputs{builds})
if err != nil {
return "", nil, fmt.Errorf("cannot marshal build artifacts: %w", err)
}
f, err := os.CreateTemp("", "builds*.yaml")
if err != nil {
return "", nil, fmt.Errorf("cannot create temp file: %w", err)
}
if _, err := f.Write(buildOutput); err != nil {
return "", nil, fmt.Errorf("cannot write to temp file: %w", err)
}
if err := f.Close(); err != nil {
return "", nil, fmt.Errorf("cannot close temp file: %w", err)
}
return f.Name(), func() { os.Remove(f.Name()) }, nil
}
// SanitizeFilePath is used to sanitize filepaths that are provided to the `setFiles` flag
// helm `setFiles` doesn't work with the unescaped filepath separator (\) for Windows or if there are unescaped tabs and spaces in the directory names.
// So we escape all odd count occurrences of `\` for Windows, and wrap the entire string in quotes if it has spaces.
// This is very specific to the way helm handles its flags.
// See https://github.com/helm/helm/blob/d55c53df4e394fb62b0514a09c57bce235dd7877/pkg/cli/values/options.
// Otherwise the windows `syscall` package implements its own sanitizing for command args that's used by `exec.Cmd`.
// See https://github.com/golang/go/blob/6951da56b0ae2cd4250fc1b0350d090aed633ac1/src/syscall/exec_windows.go#L27
func SanitizeFilePath(s string, isWindowsOS bool) string {
if len(s) == 0 {
return `""`
}
needsQuotes := false
for i := 0; i < len(s); i++ {
if s[i] == ' ' || s[i] == '\t' {View on GitHub (pinned to a1189de023)
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
Defensive patterns
Strategy: retry
Validate before calling
TD="${TMPDIR:-/tmp}"; df --output=avail "$TD" | awk 'NR==2{exit ($1<104857600)?1:0}' || { echo "free disk space before deploying"; exit 1; } Try / catch
err := deploy(); if err != nil && strings.Contains(err.Error(), "cannot close temp file") {
// often transient ENOSPC surfaced at flush; free space and retry once
if retriable(err) { err = deploy() }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- could not write build-artifacts: %w
- cannot create temp file: %w
- cannot write to temp file: %w
- strings.Join(errMsgs, "\n") (joined helm cleanup error messa
- Failed to install Helm plugin
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/483656b735ce35fb.
Report an issue: GitHub.