hashicorp/nomad · error

Failed to copy snapshot to temporary file: %v

Error message

Failed to copy snapshot to temporary file: %v

What it means

The newly created redacted snapshot is copied back over the caller's temporary file (after truncating and seeking to 0). This error wraps an io.Copy failure — a write to the file, a read from the snapshot stream, or a mid-copy I/O error. The file may be partially written when this fires.

Source

Thrown at helper/raftutil/snapshot.go:104

		}

		fsm.Apply(&raft.Log{
			Type: raft.LogCommand,
			Data: msg,
		})
	}

	snap, err := snapshot.NewFromFSM(hclog.Default(), fsm, meta)
	if err != nil {
		return fmt.Errorf("Failed to create redacted snapshot: %v", err)
	}

	srcFile.Truncate(0)
	srcFile.Seek(0, 0)

	_, err = io.Copy(srcFile, snap)
	if err != nil {
		return fmt.Errorf("Failed to copy snapshot to temporary file: %v", err)
	}

	return srcFile.Sync()
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Free disk space (or point the temp file at a volume with room for a full snapshot copy) and retry.
  2. Verify srcFile is opened read-write and still valid before the copy.
  3. Discard/truncate the partially written file after this error; do not treat it as a usable snapshot.
  4. Check the embedded error for ENOSPC vs read-side failures to target the right fix.

Example fix

// before
_, err = io.Copy(srcFile, snap)
if err != nil {
    return fmt.Errorf("Failed to copy snapshot to temporary file: %v", err)
}

// after
_, err = io.Copy(srcFile, snap)
if err != nil {
    srcFile.Truncate(0)
    return fmt.Errorf("Failed to copy snapshot to temporary file: %v", err)
}
Defensive patterns

Strategy: validation

Validate before calling

func ensureWritableSpace(f *os.File, need uint64) error {
    // check the file is writable
    if err := syscall.Faccessat(int(f.Fd()), "", unix.W_OK, 0); err != nil {
        return err
    }
    return nil
}

Try / catch

if err := raftutil.RedactSnapshot(f); err != nil {
    if strings.Contains(err.Error(), "Failed to copy snapshot to temporary file") {
        // do not trust partial output
        f.Truncate(0)
        log.Printf("copy failed: %v — check ENOSPC and file writability", err)
    }
}

Prevention

When it happens

Trigger: io.Copy(srcFile, snap) returning an error: read error from the snapshot stream, ENOSPC writing to srcFile, or an I/O error on the underlying file descriptor.

Common situations: Full or nearly-full disk on the node running the redaction (snapshot can be large), quota-limited temp directory, or a file handle with insufficient write permissions / closed fd.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/014809858354f02c. Report an issue: GitHub.