kopia/kopia · error
cannot sync temporary file in dir
Error message
cannot sync temporary file in dir %s
What it means
After successfully writing data, writeTempFileAtomicImp calls tf.Sync to force the data to stable storage before the file is renamed into place. A Sync failure is wrapped with this message, which includes the directory, and aborts the atomic write. It protects durability guarantees: content is never published unless it has been flushed.
Solutions
- Check disk space and quota on the reported directory's volume.
- Verify the filesystem supports fsync (avoid problematic network/FUSE mounts for the cache).
- Check device health (smartctl/dmesg) for recurring sync I/O errors.
- Retry after resolving; the atomic design means no corrupted half-written content was published.
Defensive patterns
Strategy: try-catch
Validate before calling
// probe fsync support before writing content
pf, _ := os.CreateTemp(cacheDir, "synctest")
if pf != nil { if err := pf.Sync(); err != nil { log.Warnf("fsync unsupported/broken on %s", cacheDir) }; pf.Close(); os.Remove(pf.Name()) } Try / catch
if err != nil && strings.Contains(err.Error(), "cannot sync temporary file in dir") {
// non-durable write was NOT published; alert and retry on healthy storage
alertStorageIssue(err)
return err
} Prevention
- Host cache/content directories on filesystems with reliable fsync (avoid problematic FUSE/NFS).
- Keep spare disk headroom so sync-time flushes do not hit ENOSPC.
- Monitor device errors (dmesg/smartctl) on backup storage hosts.
When it happens
Trigger: tf.Sync() fails on the just-written temp file: ENOSPC while flushing, EIO from the device, or unsupported-sync semantics on exotic filesystems/network mounts hosting dirname.
Common situations: Disks filling up exactly during a backup; failing storage devices; filesystems (some FUSE/network mounts) that do not support fsync properly; container volumes with flaky backing stores.
Related errors
- cannot flush file
- can't sync temporary file data
- can't close tmp file
- can't write to temp file
- error reading directory
AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07).
Data as JSON: /api/errors/6c3d2bb82601ba8c.
Report an issue: GitHub.
Appendix: source
Thrown at repo/content/write_temp_file.go:82
err = stderrors.Join(err, errors.Wrap(cerr, "can't close tmp file"))
}
if err != nil {
// remove tmp file on error to avoid leaving them behind
if rerr := fsi.Remove(tf.Name()); rerr != nil {
err = stderrors.Join(err, errors.Wrap(rerr, "can't remove tmp file"))
}
filename = ""
}
}()
if _, err2 := tf.Write(data); err2 != nil {
return "", errors.Wrap(err2, "can't write to temp file")
}
if err2 := tf.Sync(); err2 != nil {
return "", errors.Wrapf(err2, "cannot sync temporary file in dir %s", dirname)
}
return tf.Name(), nil
}
View on GitHub (pinned to 82495e54b5)