hyperledger/fabric · error

error cleaning up transient files

Error message

error cleaning up transient files

What it means

filerepo.New scans the repository directory and removes leftover transient (temp) files from prior interrupted operations. If os.Remove fails on such a file, the directory cannot be prepared and New returns this wrapped error, aborting repo creation. It indicates filesystem-level trouble removing a *.tmp file.

Source

Thrown at orderer/common/filerepo/filerepo.go:65

	if err := fileutil.SyncDir(repoParentDir); err != nil {
		return nil, err
	}

	files, err := os.ReadDir(fileRepoDir)
	if err != nil {
		return nil, err
	}

	// Remove existing transient files in the repo
	transientFilePattern := "*" + fileSuffix + defaultTransientFileMarker
	for _, f := range files {
		isTransientFile, err := filepath.Match(transientFilePattern, f.Name())
		if err != nil {
			return nil, err
		}
		if isTransientFile {
			if err := os.Remove(filepath.Join(fileRepoDir, f.Name())); err != nil {
				return nil, errors.Wrapf(err, "error cleaning up transient files")
			}
		}
	}

	if err := fileutil.SyncDir(fileRepoDir); err != nil {
		return nil, err
	}

	return &Repo{
		transientFileMarker: defaultTransientFileMarker,
		fileSuffix:          fileSuffix,
		fileRepoDir:         fileRepoDir,
	}, nil
}

// Save atomically persists the content to suffix/baseName+suffix file by first writing it
// to a tmp file marked by the transientFileMarker and then moves the file to the final
// destination indicated by the FileSuffix.

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Check permissions on the file repo directory and its *.tmp files and remove them manually with sufficient privileges
  2. Verify the orderer process is the only one using the data directory and stop any duplicate process
  3. Ensure the filesystem (e.g. Docker volume/host mount) is writable, not read-only, and has free space
  4. Re-run the orderer; if the volume persists across restarts, fix ownership (chown) to the user the orderer runs as

Example fix

// before (orderer cannot delete transient file)
os.Remove(filepath.Join(fileRepoDir, f.Name())) // permission denied
// after (shell, as the operator)
sudo chown -R orderer:orderer /var/hyperledger/production/orderer
rm -f /var/hyperledger/production/orderer/*/*.tmp
Defensive patterns

Strategy: validation

Validate before calling

dir := "/var/hyperledger/production/orderer"
info, err := os.Stat(dir)
if err != nil || !info.IsDir() {
    panic("file repo dir missing")
}
if err := unix.Access(dir, unix.W_OK); err != nil {
    panic("file repo dir not writable by current user")
}
matches, _ := filepath.Glob(filepath.Join(dir, "*", "*.tmp"))
for _, m := range matches {
    if err := os.Remove(m); err != nil {
        panic("cannot remove transient file: " + m)
    }
}

Try / catch

repo, err := filerepo.New(dir, suffix)
if err != nil {
    if strings.Contains(err.Error(), "error cleaning up transient files") {
        logger.Fatalf("stale transient files not removable, check permissions on %s: %v", dir, err)
    }
    return err
}

Prevention

When it happens

Trigger: Creating a Repo (e.g. via New in serve) when the repo directory contains a file matching the transient pattern that cannot be deleted: read-only filesystem, permissions missing on the file or directory, or the file is held open by another process.

Common situations: Orderer runs as non-root but owns files from a prior run as root (or vice versa); read-only or full disk mounts; stale temp files locked by a concurrently running orderer on the same data directory.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/15315a676b64bc47. Report an issue: GitHub.