siyuan-note/siyuan · critical

flush data [ ] failed

Error message

flush data [%s] failed: %s

What it means

WriteFileByMmap memory-maps a file, copies data into the mapping, then calls m.Flush() (msync/msync-equivalent) to force the mapping back to disk. When the OS-level flush of the mapped pages fails (msync/FlushViewOfFile returns an error), the error is wrapped as "flush data [%s] failed: %s" and returned. This usually signals disk full, an I/O error, or the underlying file being truncated/removed externally between Map and Flush.

Solutions

  1. Free disk space / resolve quota on the volume hosting the workspace and retry the write
  2. Check the embedded OS error in the message (e.g. errno 28 ENOSPC, 5 EIO) and address that underlying cause
  3. Move the workspace off unreliable network/overlay filesystems to a local disk
  4. Let the caller fall back to filelock.WriteFile (the documented fallback path in the code comment) to complete the write
  5. Check dmesg/Event Viewer for storage device errors and repair or replace failing hardware

Example fix

// before
copied := make([]byte, len(data))
util.WriteFileByMmap(path, copied) // fails on full disk, error dropped
// after
if err := util.WriteFileByMmap(path, data); err != nil {
    logging.LogErrorf("mmap write failed, falling back: %s", err)
    if err2 := filelock.WriteFile(path, data); err2 != nil {
        return fmt.Errorf("write %s failed: %w", path, err2)
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: check writable space and file health before mmap write
if st, err := os.Stat(filepath.VolumeName(filePath) + string(os.PathSeparator)); err == nil {
    _ = st // monitor free space via syscall.Statfs on POSIX
}
if fi, err := os.Stat(filePath); err == nil && fi.Size() != int64(len(data)) {
    // WriteFileByMmap truncates to len(data); oversized shrink may indicate external tampering
    logging.LogWarnf("file size %d != data size %d", fi.Size(), len(data))
}

Try / catch

if err := util.WriteFileByMmap(path, data); err != nil {
    if strings.Contains(err.Error(), "flush data") {
        logging.LogErrorf("mmap flush failed for %s, retrying via filelock.WriteFile: %s", path, err)
        if fbErr := filelock.WriteFile(path, data); fbErr != nil {
            return fmt.Errorf("persistent write failure for %s: %w", path, fbErr)
        }
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Calling util.WriteFileByMmap(path, data) (used by saveAttributeView and treenode.WriteTree) when msync fails: disk full on the volume, underlying storage I/O error, file shrunk or deleted by another process after mapping, or mmap flush unsupported on the filesystem (e.g. some network filesystems).

Common situations: Disk quota exhausted while SiYuan writes attribute-view (.av) or .sy files; running the workspace on a NAS/network mount that fails msync; antivirus or sync tools (OneDrive/Dropbox) touching the file mid-write; failing disk sectors.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/7913e8c71d5ff074. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/mmap.go:64

		logging.LogError(msg)
		err = errors.New(msg)
		return
	}

	m, err := mmap.Map(f, mmap.RDWR, 0)
	if err != nil {
		msg := fmt.Sprintf("map file [%s] failed: %s", filePath, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}
	defer m.Unmap()

	copy(m, data)
	if err = m.Flush(); err != nil {
		msg := fmt.Sprintf("flush data [%s] failed: %s", filePath, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}
	return
}

View on GitHub (pinned to 9f775e8a12)