fatedier/frp · error

failed to close temp file: %w

Error message

failed to close temp file: %w

What it means

Closing the temp file failed after write and fsync succeeded. Because fsync already flushed data, this is the rarest failure of the atomic-write sequence; it surfaces delayed writeback errors or fd-level problems. The temp file is removed and the change rolled back.

Source

Thrown at pkg/config/source/store.go:169

	if err != nil {
		return fmt.Errorf("failed to create temp file: %w", err)
	}

	if _, err := f.Write(data); err != nil {
		f.Close()
		os.Remove(tmpPath)
		return fmt.Errorf("failed to write temp file: %w", err)
	}

	if err := f.Sync(); err != nil {
		f.Close()
		os.Remove(tmpPath)
		return fmt.Errorf("failed to sync temp file: %w", err)
	}

	if err := f.Close(); err != nil {
		os.Remove(tmpPath)
		return fmt.Errorf("failed to close temp file: %w", err)
	}

	if err := os.Rename(tmpPath, s.config.Path); err != nil {
		os.Remove(tmpPath)
		return fmt.Errorf("failed to rename temp file: %w", err)
	}

	return nil
}

func (s *StoreSource) persistOrRollbackUnlocked(rollback func()) error {
	if err := s.saveToFileUnlocked(); err != nil {
		rollback()
		return fmt.Errorf("failed to persist: %w", err)
	}
	return nil
}

View on GitHub (pinned to 6c8a8d0a97)

Solutions

  1. Treat it like a storage-health signal: check dmesg for I/O errors
  2. Verify the filesystem with fsck (unmounted) or move the store to a local healthy volume
  3. Retry the operation after remediation; state was rolled back consistently
Defensive patterns

Strategy: try-catch

Try / catch

if err := store.RemoveProxy(name); err != nil {
	if strings.Contains(err.Error(), "failed to close temp file") {
		// fsync already succeeded; verify the file on disk and retry once
	} else {
		return err
	}
}

Prevention

When it happens

Trigger: A writeback error deferred until close(2); file descriptor issues in unusual runtimes; almost never triggered by user input or permissions.

Common situations: Same class as sync/write errors — failing storage or exotic filesystems; otherwise negligible probability.

Related errors


AI-assisted analysis of fatedier/frp@6c8a8d0a97 (2026-08-15). Data as JSON: /api/errors/0791b4b1d4f35d65. Report an issue: GitHub.