{"record":{"id":"51fd4af1b15d6589","repo":"kubernetes/kops","slug":"error-creating-temporary-file-for-download-q-v","errorCode":null,"errorMessage":"error creating temporary file for download %q: %v","messagePattern":"error creating temporary file for download %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/http.go","lineNumber":61,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\tif match {\n\t\t\treturn hash, nil\n\t\t}\n\t}\n\n\treturn downloadURLToFile(ctx, url, dest, hash)\n}\n\nfunc downloadURLToFile(ctx context.Context, url string, destPath string, hash *hashing.Hash) (*hashing.Hash, error) {\n\tdir := filepath.Dir(destPath)\n\tif err := os.MkdirAll(dir, 0o755); err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating directories for destination file %q: %v\", destPath, err)\n\t}\n\n\toutput, err := os.CreateTemp(dir, \".\"+filepath.Base(destPath)+\".tmp\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating temporary file for download %q: %v\", destPath, err)\n\t}\n\ttempPath := output.Name()\n\tdefer os.Remove(tempPath)\n\n\tactual, err := downloadURLToWriter(ctx, url, output, hash)\n\tif closeErr := output.Close(); closeErr != nil && err == nil {\n\t\terr = closeErr\n\t}\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err := os.Chmod(tempPath, 0o644); err != nil {\n\t\treturn nil, fmt.Errorf(\"error setting mode on downloaded file %q: %v\", tempPath, err)\n\t}\n\tif err := os.Rename(tempPath, destPath); err != nil {\n\t\treturn nil, fmt.Errorf(\"error moving downloaded file %q to %q: %v\", tempPath, destPath, err)\n\t}\n\treturn actual, nil","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/http.go#L43-L79","documentation":"The downloader creates a hidden temp file ('.<base>.tmp') in the destination directory via os.CreateTemp, then downloads into it before an atomic rename. Failure to create the temp file (usually permissions or no space) is wrapped with this message.","triggerScenarios":"os.CreateTemp(dir, \".\"+base+\".tmp\") fails: destination dir not writable, disk full, or too many open files.","commonSituations":"Read-only or non-writable target directory; ENOSPC on the partition; file-descriptor limits hit during large operations.","solutions":["Check disk space (df -h) and free space if ENOSPC","Verify the destination directory is writable by the current user","Check ulimit -n if 'too many open files' appears in the wrapped error","Point the download at a writable directory"],"exampleFix":"// before\ndf -h /usr/local  -> 100% full\n// after\nclean up disk space or choose a different destination, then retry the download","handlingStrategy":"validation","validationCode":"// Check writability and free space of the target directory first\nif err := unix.Access(dir, unix.W_OK); err != nil { return err }\n// and: df -h <dir> / statfs for available space before large downloads","typeGuard":null,"tryCatchPattern":"if _, err := fi.DownloadURL(ctx, url, dest, nil); err != nil {\n    var se *os.PathError\n    if errors.As(err, &se) && errors.Is(se.Err, syscall.ENOSPC) {\n        return fmt.Errorf(\"disk full while downloading %s\", dest)\n    }\n    return err\n}","preventionTips":["Monitor disk space on partitions used for kops assets","Keep .tmp-file cleanup jobs from racing active downloads","Ensure the download directory is writable by the provisioning user"],"tags":["filesystem","temp-file","download"],"backgroundTag":"disk-full","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}