{"record":{"id":"63c5dd1b71168469","repo":"shadow1ng/fscan","slug":"failed-to-sync-realtime-backup-w","errorCode":null,"errorMessage":"failed to sync realtime backup: %w","messagePattern":"failed to sync realtime backup: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/output/writers.go","lineNumber":140,"sourceCode":"\n\tif w.closed {\n\t\treturn fmt.Errorf(\"writer is closed\")\n\t}\n\tif result == nil {\n\t\treturn fmt.Errorf(\"result cannot be nil\")\n\t}\n\n\t// 1. 加入内存分类缓冲（用于最终有序输出）\n\tw.buffer.Add(result)\n\n\t// 2. 实时写入备份文件（防崩溃丢数据）\n\tif w.realtimeFile != nil {\n\t\tline := w.formatLine(result)\n\t\tif _, err := w.realtimeFile.WriteString(line + \"\\n\"); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write realtime backup: %w\", err)\n\t\t}\n\t\tif err := w.realtimeFile.Sync(); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to sync realtime backup: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// getSeparator 获取分隔线文本\nfunc (w *TXTWriter) getSeparator(newType ResultType) string {\n\tswitch newType {\n\tcase TypeHost:\n\t\treturn i18n.GetText(\"output_section_hosts\")\n\tcase TypePort:\n\t\treturn i18n.GetText(\"output_section_ports\")\n\tcase TypeService:\n\t\treturn i18n.GetText(\"output_section_services\")\n\tcase TypeVuln:\n\t\treturn i18n.GetText(\"output_section_vulns\")\n\tdefault:","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/output/writers.go#L122-L158","documentation":"Returned when fsync on the realtime backup file fails after a successful WriteString. The library calls Sync() on every write to guarantee crash-safe persistence of scan results, so any flush-to-disk failure is reported. It wraps the underlying OS error.","triggerScenarios":"Calling Write() on a writer with realtimeFile != nil where w.realtimeFile.Sync() returns an error: fsync failing on disk full, I/O error, or on certain filesystems/network mounts that do not support fsync.","commonSituations":"Output written to NFS or FUSE mounts with unreliable fsync; disk failure or ENOSPC surfacing only at sync time; container with restricted I/O on the volume.","solutions":["Check dmesg/system logs for underlying disk I/O errors","Verify available disk space and volume health","If writing to a network filesystem, move output to local disk or accept weaker durability","Inspect the wrapped OS error via errors.Is/Unwrap to confirm the cause","Retry the write or restart the writer after the storage issue is fixed"],"exampleFix":"// before\nif err := w.realtimeFile.Sync(); err != nil {\n\treturn fmt.Errorf(\"failed to sync realtime backup: %w\", err)\n}\n// after\nif err := w.realtimeFile.Sync(); err != nil {\n\tif isNetworkFS(w.realtimePath) { // tolerate fsync on NFS-like mounts\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"failed to sync realtime backup: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"info, err := os.Stat(outDir)\nif err != nil || !info.IsDir() { return fmt.Errorf(\"output dir missing\") }\nif unix.Access(outDir, unix.W_OK) != nil { return fmt.Errorf(\"output dir not writable\") }","typeGuard":null,"tryCatchPattern":"if err := writer.Write(result); err != nil {\n\tif strings.Contains(err.Error(), \"failed to sync realtime backup\") {\n\t\tlog.Printf(\"fsync failed; durability compromised: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Write realtime backups to local disk, not NFS/FUSE mounts","Monitor disk health (SMART) on storage used for output","Handle ENOSPC proactively with free-space checks","Decide durability requirements up front; disable per-write sync if unnecessary","Log wrapped OS errors for post-mortem diagnosis"],"tags":["go","file-io","fsync"],"backgroundTag":"file-write-failed","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}