{"record":{"id":"1ee191e29103c81d","repo":"lima-vm/lima","slug":"failed-to-stat-raw-tmp-file-q-w","errorCode":null,"errorMessage":"failed to stat raw tmp file %q: %w","messagePattern":"failed to stat raw tmp file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/downloader/downloader.go","lineNumber":487,"sourceCode":"\trawImgConvPath := filepath.Join(imgConvPath, \"raw\")\n\n\tlogrus.Infof(\"Converting %s image to raw sparse format in cache: %q\", format, rawImgConvPath)\n\trawPathTmp := filepath.Join(imgConvPath, \"raw.tmp\")\n\tdefer os.Remove(rawPathTmp)\n\tdiskUtil := proxyimgutil.NewDiskUtil(ctx)\n\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()","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/downloader/downloader.go#L469-L505","documentation":"Immediately after opening the converted raw temp file, ensureRawInCache calls Stat() to obtain its size for MakeSparse. A Stat failure (wrapped and with the file descriptor closed) aborts finalization of the sparse raw image.","triggerScenarios":"rawTmpF.Stat() returns an error in ensureRawInCache — rare; usually caused by the file being deleted/unlinked concurrently while open, or filesystem-level I/O errors on the cache volume.","commonSituations":"Concurrent cache pruning (another limactl or cleanup script removing raw.tmp) during a download; failing/flaky disk or network mount hosting the cache.","solutions":["Rerun the download; the error is usually transient (concurrent deletion).","Ensure no cleanup job removes files under the cache directory while downloads are running.","Check the health of the filesystem hosting CacheDir (dmesg, smartctl)."],"exampleFix":"// before: cron job wiping cache mid-download\n# cron: 0 * * * * rm -rf ~/.cache/lima/images/*\n// after: prune only stale entries, not during active use\n# use limactl's cache prune or guard with a lock","handlingStrategy":"retry","validationCode":"// ensure no concurrent cache pruners are running before a long download\nif isCachePrunerRunning() { return errors.New(\"suspend cache cleanup during downloads\") }","typeGuard":null,"tryCatchPattern":"res, err := d.Download(ctx, local, url)\nif err != nil && strings.Contains(err.Error(), \"failed to stat raw tmp file\") {\n    time.Sleep(time.Second)\n    res, err = d.Download(ctx, local, url) // retry: usually a transient concurrent deletion\n}","preventionTips":["Do not run cache-cleanup jobs while downloads are active.","Use a single downloader process per cache directory.","Check filesystem health if Stat errors recur."],"tags":["downloader","file-io","stat","cache"],"backgroundTag":"cache-io-error","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}