{"record":{"id":"224a2b2caacce6c8","repo":"kopia/kopia","slug":"error-closing-cache-marker-file","errorCode":null,"errorMessage":"error closing cache marker file","messagePattern":"error closing cache marker file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/cachedir/cachedir.go","lineNumber":56,"sourceCode":"\tif err == nil && st.Size() >= int64(len(cacheDirMarkerContents)) {\n\t\t// ok\n\t\treturn nil\n\t}\n\n\tif err != nil && !os.IsNotExist(err) {\n\t\treturn errors.Wrap(err, \"unexpected cache marker error\")\n\t}\n\n\tf, err := os.Create(markerFile) //nolint:gosec\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"error creating cache marker\")\n\t}\n\n\tif _, err := f.WriteString(cacheDirMarkerContents); err != nil {\n\t\treturn errors.Wrap(err, \"unable to write cachedir marker contents\")\n\t}\n\n\treturn errors.Wrap(f.Close(), \"error closing cache marker file\")\n}\n","sourceCodeStart":38,"sourceCodeEnd":58,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/internal/cachedir/cachedir.go#L38-L58","documentation":"WriteCacheMarker finishes with f.Close(); a non-nil close error is wrapped as \"error closing cache marker file\". On some filesystems Close is where write-back errors surface, meaning the marker contents may not have actually been flushed to stable storage.","triggerScenarios":"WriteCacheMarker when f.Close() returns an error: deferred write-back failures (ENOSPC/EIO surfaced at close), network volume connection lost mid-operation, or filesystem-level errors on removable media.","commonSituations":"NFS/SMB cache mounts dropped mid-write; full disk where buffered writes only fail at flush/close; flaky external drives holding the cache.","solutions":["Treat the marker as unwritten: remove the cache directory and retry after checking the volume.","Verify disk space and device health (dmesg, SMART) on the cache volume.","Move the cache from network/removable storage to local disk.","Retry the operation once the volume is healthy; the marker is recreated automatically."],"exampleFix":"// before\ncache on /mnt/nfs-cache -> error closing cache marker file: input/output error\n// after\nkopia cache set --cache-directory ~/.cache/kopia  # local disk","handlingStrategy":"try-catch","validationCode":"// ensure the volume is local/reliable before caching\nif fi, err := os.Stat(dir); err != nil || !fi.IsDir() {\n    return errors.New(\"cache path must be an existing local directory\")\n}","typeGuard":null,"tryCatchPattern":"if err := cachedir.WriteCacheMarker(dir, false); err != nil {\n    if strings.Contains(err.Error(), \"error closing cache marker file\") {\n        log.Warnf(\"marker close failed (write-back error on %s): %v\", dir, err)\n        // remove the suspect cache dir and recreate on local storage\n        _ = os.RemoveAll(dir)\n    }\n    return err\n}","preventionTips":["Place cache directories on local disks, not NFS/SMB/removable media.","Investigate any close-time I/O error immediately — it often signals failing hardware.","Check dmesg/SMART when close errors appear.","Recreate the cache directory after such failures; the marker is rewritten on next use."],"tags":["cache","file-close","io","cachedir-marker","kopia"],"backgroundTag":"file-write-failed","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}