{"record":{"id":"75305d155e331a99","repo":"fatedier/frp","slug":"failed-to-sync-temp-file-w","errorCode":null,"errorMessage":"failed to sync temp file: %w","messagePattern":"failed to sync temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/source/store.go","lineNumber":164,"sourceCode":"\t}\n\n\ttmpPath := s.config.Path + \".tmp\"\n\n\tf, err := os.OpenFile(tmpPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\n\tif _, err := f.Write(data); err != nil {\n\t\tf.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to write temp file: %w\", err)\n\t}\n\n\tif err := f.Sync(); err != nil {\n\t\tf.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to sync temp file: %w\", err)\n\t}\n\n\tif err := f.Close(); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to close temp file: %w\", err)\n\t}\n\n\tif err := os.Rename(tmpPath, s.config.Path); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to rename temp file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (s *StoreSource) persistOrRollbackUnlocked(rollback func()) error {\n\tif err := s.saveToFileUnlocked(); err != nil {\n\t\trollback()","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/config/source/store.go#L146-L182","documentation":"f.Sync() (fsync) on the temp file failed after a successful write. The library fsyncs deliberately so the store never loses acknowledged writes on crash; a sync error usually indicates a filesystem-level problem, not bad input.","triggerScenarios":"EIO from a failing disk or degraded RAID; fsync on a filesystem/mount that does not support it correctly (some FUSE/network mounts, certain container overlays); vm writeback errors surfaced at fsync time.","commonSituations":"FUSE/NFS-backed store paths in containers; dying SD-card/eMMC deployments (edge gateways); kernel writeback errors after storage disconnect.","solutions":["Check kernel logs: dmesg | grep -i 'fsync\\|I/O error'","Move the store to a healthy local filesystem (ext4/xfs) if it currently sits on network/FUSE storage","Run storage diagnostics (smartctl -a) and replace failing hardware","After fixing storage, retry the operation — rollback kept in-memory state consistent with the file"],"exampleFix":"# before: store on FUSE mount that fails fsync\nPath: /mnt/nas/frpc/store.json\n\n# after: local writable path\nPath: /var/lib/frpc/store.json","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := store.UpdateProxy(cfg)\nif err != nil && errors.Is(err, syscall.EIO) {\n\t// transient fs error: surface it; retry only after confirming storage health\n\t// state was rolled back, so a plain retry of UpdateProxy is safe\n}","preventionTips":["Keep the store file on a healthy local filesystem (ext4/xfs), not FUSE or flaky network mounts","Watch dmesg/SMART for I/O errors on hosts running the store","Because rollback keeps memory and file consistent, a retry after remediation is always safe"],"tags":["filesystem","io","fsync","storage-health","go"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}