{"record":{"id":"932e6e48fb0e3fd2","repo":"lima-vm/lima","slug":"failed-to-close-raw-tmp-file-q-w","errorCode":null,"errorMessage":"failed to close raw tmp file %q: %w","messagePattern":"failed to close raw tmp file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/downloader/downloader.go","lineNumber":493,"sourceCode":"\tif err := diskUtil.Convert(ctx, raw.Type, imagePath, rawPathTmp, nil, false); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to convert %q to raw: %w\", imagePath, err)\n\t}\n\n\t// Ensure the image is sparse to save cache space.\n\trawTmpF, err := os.OpenFile(rawPathTmp, os.O_RDWR, 0o644)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to open raw tmp file %q: %w\", rawPathTmp, err)\n\t}\n\tfi, err := rawTmpF.Stat()\n\tif err != nil {\n\t\t_ = rawTmpF.Close()\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to stat raw tmp file %q: %w\", rawPathTmp, err)\n\t}\n\tif err := diskUtil.MakeSparse(ctx, rawTmpF, fi.Size()); err != nil {\n\t\tlogrus.WithError(err).Warnf(\"Failed to make %q sparse (non-fatal)\", rawPathTmp)\n\t}\n\tif err := rawTmpF.Close(); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to close raw tmp file %q: %w\", rawPathTmp, err)\n\t}\n\n\tif err := os.Remove(rawImgConvPath); err != nil && !errors.Is(err, os.ErrNotExist) {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to remove stale raw image %q: %w\", rawImgConvPath, err)\n\t}\n\tif err := os.Rename(rawPathTmp, rawImgConvPath); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to replace original with raw image: %w\", err)\n\t}\n\n\talgo := digest.Canonical\n\tif originalDigest != \"\" {\n\t\talgo = originalDigest.Algorithm()\n\t}\n\trawDigest, err := calculateFileDigest(rawImgConvPath, algo)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to calculate digest of raw image: %w\", err)\n\t}\n","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/downloader/downloader.go#L475-L511","documentation":"ensureRawInCache converts a downloaded VM disk image to a sparse raw copy under <cache>/imgconv/raw. After making the tmp file sparse, it closes the file descriptor; if Close() reports an error (often a deferred flush/writeback failure or EIO), the operation is aborted with this message wrapping the OS error. Close errors on freshly-written files usually indicate disk problems, since buffered data may be flushed at close time.","triggerScenarios":"Downloading a non-ISO disk image whose format is not in the WithImageFormats() list, so ensureRawInCache runs and closes imgconv/raw.tmp; Close() returns a non-nil error (e.g. ENOSPC flushed at close, EIO, or file already closed by an underlying bug).","commonSituations":"Host disk nearly full so sparse-writeback fails at close; NFS/network filesystems where close can report I/O errors; corrupted cache directory on removable media that was unplugged mid-download.","solutions":["Check host disk space with df on the LIMA_HOME/cache volume and free space, then retry the download","Verify the cache directory is on reliable local storage, not a flaky network mount; move cacheDir to a local disk","Delete the instance/cache entry (imgconv dir) to force a clean re-conversion","Check dmesg/filesystem health (fsck) for underlying I/O errors if the problem repeats"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight: ensure cache volume has free space and is writable\nfi, err := os.Stat(cacheDir)\nif err != nil || !fi.IsDir() { return fmt.Errorf(\"cache dir unusable: %w\", err) }\nif err := unix.Access(cacheDir, unix.W_OK); err != nil { return fmt.Errorf(\"cache dir not writable: %w\", err) }","typeGuard":null,"tryCatchPattern":"res, err := downloader.Download(url, opts...)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to close raw tmp file\") {\n        // check disk space / fs health, clear imgconv dir, retry once\n        os.RemoveAll(filepath.Join(cacheDir, \"download\"))\n    }\n    return err\n}","preventionTips":["Keep the Lima cache volume (LIMA_HOME/_cache) on reliable local disk with ample free space","Monitor disk usage before large image downloads","Run periodic fsck/smart checks on the host volume","Clear imgconv directories after failed conversions"],"tags":["go","filesystem","cache","io"],"backgroundTag":"file-close-io-error","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}