{"record":{"id":"6c3d2bb82601ba8c","repo":"kopia/kopia","slug":"cannot-sync-temporary-file-in-dir-s","errorCode":null,"errorMessage":"cannot sync temporary file in dir %s","messagePattern":"cannot sync temporary file in dir (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/content/write_temp_file.go","lineNumber":82,"sourceCode":"\t\t\terr = stderrors.Join(err, errors.Wrap(cerr, \"can't close tmp file\"))\n\t\t}\n\n\t\tif err != nil {\n\t\t\t// remove tmp file on error to avoid leaving them behind\n\t\t\tif rerr := fsi.Remove(tf.Name()); rerr != nil {\n\t\t\t\terr = stderrors.Join(err, errors.Wrap(rerr, \"can't remove tmp file\"))\n\t\t\t}\n\n\t\t\tfilename = \"\"\n\t\t}\n\t}()\n\n\tif _, err2 := tf.Write(data); err2 != nil {\n\t\treturn \"\", errors.Wrap(err2, \"can't write to temp file\")\n\t}\n\n\tif err2 := tf.Sync(); err2 != nil {\n\t\treturn \"\", errors.Wrapf(err2, \"cannot sync temporary file in dir %s\", dirname)\n\t}\n\n\treturn tf.Name(), nil\n}\n","sourceCodeStart":64,"sourceCodeEnd":87,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/content/write_temp_file.go#L64-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// probe fsync support before writing content\npf, _ := os.CreateTemp(cacheDir, \"synctest\")\nif pf != nil { if err := pf.Sync(); err != nil { log.Warnf(\"fsync unsupported/broken on %s\", cacheDir) }; pf.Close(); os.Remove(pf.Name()) }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"cannot sync temporary file in dir\") {\n    // non-durable write was NOT published; alert and retry on healthy storage\n    alertStorageIssue(err)\n    return err\n}","preventionTips":["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."],"tags":["filesystem","fsync","durability","io"],"backgroundTag":"file-sync-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"}