gastownhall/beads · error
atomicfile: sync: %w
Error message
atomicfile: sync: %w
What it means
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.
Source
Thrown at internal/atomicfile/atomicfile.go:85
// After Close returns successfully, the target contains exactly the data
// written. On error the temp file is removed and the target is untouched.
func (w *Writer) Close() error {
if w.done {
return nil
}
w.done = true
// Ensure permissions before rename — CreateTemp uses 0600 by default.
if err := w.f.Chmod(w.perm); err != nil {
_ = w.f.Close()
_ = os.Remove(w.f.Name())
return fmt.Errorf("atomicfile: chmod: %w", err)
}
if err := w.f.Sync(); err != nil {
_ = w.f.Close()
_ = os.Remove(w.f.Name())
return fmt.Errorf("atomicfile: sync: %w", err)
}
if err := w.f.Close(); err != nil {
_ = os.Remove(w.f.Name())
return fmt.Errorf("atomicfile: close: %w", err)
}
if err := os.Rename(w.f.Name(), w.target); err != nil {
_ = os.Remove(w.f.Name())
return fmt.Errorf("atomicfile: rename: %w", err)
}
return nil
}
// Abort discards the temp file without renaming. The target is untouched.
// Safe to call multiple times or after Close.
func (w *Writer) Abort() error {View on GitHub (pinned to 71377f2769)
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
Defensive patterns
Strategy: try-catch
Try / catch
if err := w.Close(); err != nil {
if strings.Contains(err.Error(), "atomicfile: sync") {
log.Printf("fsync failed (fs/hardware issue?): %v", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: Running inside containers on filesystems without proper fsync support, USB/NFS mounts with I/O errors, or hardware failure during a large export.
Related errors
- failed to create temp file: %w
- failed to sync temp file: %w
- failed to close temp file: %w
- failed to rename temp file: %w
- ensureProxiedServerConfig: write %s: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/f127710030cce015.
Report an issue: GitHub.