{"record":{"id":"f127710030cce015","repo":"gastownhall/beads","slug":"atomicfile-sync-w","errorCode":null,"errorMessage":"atomicfile: sync: %w","messagePattern":"atomicfile: sync: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/atomicfile/atomicfile.go","lineNumber":85,"sourceCode":"// After Close returns successfully, the target contains exactly the data\n// written. On error the temp file is removed and the target is untouched.\nfunc (w *Writer) Close() error {\n\tif w.done {\n\t\treturn nil\n\t}\n\tw.done = true\n\n\t// Ensure permissions before rename — CreateTemp uses 0600 by default.\n\tif err := w.f.Chmod(w.perm); err != nil {\n\t\t_ = w.f.Close()\n\t\t_ = os.Remove(w.f.Name())\n\t\treturn fmt.Errorf(\"atomicfile: chmod: %w\", err)\n\t}\n\n\tif err := w.f.Sync(); err != nil {\n\t\t_ = w.f.Close()\n\t\t_ = os.Remove(w.f.Name())\n\t\treturn fmt.Errorf(\"atomicfile: sync: %w\", err)\n\t}\n\n\tif err := w.f.Close(); err != nil {\n\t\t_ = os.Remove(w.f.Name())\n\t\treturn fmt.Errorf(\"atomicfile: close: %w\", err)\n\t}\n\n\tif err := os.Rename(w.f.Name(), w.target); err != nil {\n\t\t_ = os.Remove(w.f.Name())\n\t\treturn fmt.Errorf(\"atomicfile: rename: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// Abort discards the temp file without renaming. The target is untouched.\n// Safe to call multiple times or after Close.\nfunc (w *Writer) Abort() error {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/atomicfile/atomicfile.go#L67-L103","documentation":"Writer.Close fsyncs the temp file so its contents survive a crash before the rename. If f.Sync() fails, Close closes and removes the temp file and returns this wrapped error; the target file is never modified.","triggerScenarios":"Sync fails when the underlying file handle is bad, the filesystem does not support fsync (some overlay/FUSE/network filesystems), or I/O errors occur (failing disk, full journal).","commonSituations":"Running inside containers on filesystems without proper fsync support, USB/NFS mounts with I/O errors, or hardware failure during a large export.","solutions":["Check kernel/dmesg or mount logs for underlying I/O errors and replace failing hardware","Move the write target to a filesystem with reliable fsync (local disk)","If the mount genuinely can't fsync, write to a local temp dir and copy/move into place"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := w.Close(); err != nil {\n    if strings.Contains(err.Error(), \"atomicfile: sync\") {\n        log.Printf(\"fsync failed (fs/hardware issue?): %v\", err)\n    }\n    return err\n}","preventionTips":["Monitor dmesg/storage health on hosts running bd exports","Keep the target on local storage with reliable fsync","Treat sync errors as serious: data may not be durable; never ignore them"],"tags":["filesystem","durability","fsync","atomic-write"],"backgroundTag":"fsync-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}