{"record":{"id":"2c8fd02865319f27","repo":"dgraph-io/dgraph","slug":"while-syncing-file-s","errorCode":null,"errorMessage":"while syncing file: %s","messagePattern":"while syncing file: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/backup_handler.go","lineNumber":201,"sourceCode":"\t\treturn true\n\t})\n}\nfunc (h *fileHandler) CreateDir(path string) error {\n\tpath = h.JoinPath(path)\n\tif err := os.MkdirAll(path, 0755); err != nil {\n\t\treturn errors.Errorf(\"Create path failed to create path %s, got error: %v\", path, err)\n\t}\n\treturn nil\n}\n\ntype fileSyncer struct {\n\tfp *os.File\n}\n\nfunc (fs *fileSyncer) Write(p []byte) (n int, err error) { return fs.fp.Write(p) }\nfunc (fs *fileSyncer) Close() error {\n\tif err := fs.fp.Sync(); err != nil {\n\t\treturn errors.Wrapf(err, \"while syncing file: %s\", fs.fp.Name())\n\t}\n\terr := fs.fp.Close()\n\treturn errors.Wrapf(err, \"while closing file: %s\", fs.fp.Name())\n}\n\nfunc (h *fileHandler) CreateFile(path string) (io.WriteCloser, error) {\n\tpath = h.JoinPath(path)\n\tfp, err := os.Create(path)\n\treturn &fileSyncer{fp}, errors.Wrapf(err, \"File handler failed to create file %s\", path)\n}\n\nfunc (h *fileHandler) Rename(src, dst string) error {\n\tsrc = h.JoinPath(src)\n\tdst = h.JoinPath(dst)\n\treturn os.Rename(src, dst)\n}\n\n// pathExist checks if a path (file or dir) is found at target.","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/backup_handler.go#L183-L219","documentation":"fileSyncer.Close calls fsync on the underlying *os.File before closing; if Sync fails the error is wrapped as 'while syncing file: <name>'. This guarantees backup data actually hit disk; a failure means data durability is not guaranteed for that file.","triggerScenarios":"fs.fp.Sync() returns an error — typically ENOSPC/EIO on writeback, EROFS, or device I/O errors during fsync of a backup file just written.","commonSituations":"Disk full discovered at fsync time; failing disk or controller; NFS reporting stale file handles; container storage driver errors.","solutions":["Read the wrapped cause and file name; check dmesg/kern.log for I/O errors on that device.","Free disk space — fsync commonly surfaces ENOSPC not seen at write time.","If the device reports I/O errors, stop using it, re-mount or replace hardware, and restore from a known-good backup.","Retry the backup after fixing storage; the partially synced file must be considered corrupt/untrusted."],"exampleFix":"// before\nif err := fs.fp.Sync(); err != nil {\n    return errors.Wrapf(err, \"while syncing file: %s\", fs.fp.Name())\n}\n// after\nif err := fs.fp.Sync(); err != nil {\n    os.Remove(fs.fp.Name()) // don't leave a possibly-corrupt backup\n    return errors.Wrapf(err, \"while syncing file: %s\", fs.fp.Name())\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := wc.Close(); err != nil {\n    if strings.Contains(err.Error(), \"while syncing file\") {\n        log.Printf(\"CRITICAL: backup file not durably synced: %v — treat as failed\", err)\n        os.Remove(backupPath)\n        return err\n    }\n    return err\n}","preventionTips":["Monitor disk space proactively; fsync failures often surface only at close.","Run SMART monitoring on backup storage.","Treat files whose Close() failed as invalid — never register them as backups.","Prefer local disks over flaky network mounts for backup staging."],"tags":["filesystem","fsync","durability"],"backgroundTag":"fsync-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}