{"record":{"id":"014809858354f02c","repo":"hashicorp/nomad","slug":"failed-to-copy-snapshot-to-temporary-file-v","errorCode":null,"errorMessage":"Failed to copy snapshot to temporary file: %v","messagePattern":"Failed to copy snapshot to temporary file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/raftutil/snapshot.go","lineNumber":104,"sourceCode":"\t\t}\n\n\t\tfsm.Apply(&raft.Log{\n\t\t\tType: raft.LogCommand,\n\t\t\tData: msg,\n\t\t})\n\t}\n\n\tsnap, err := snapshot.NewFromFSM(hclog.Default(), fsm, meta)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to create redacted snapshot: %v\", err)\n\t}\n\n\tsrcFile.Truncate(0)\n\tsrcFile.Seek(0, 0)\n\n\t_, err = io.Copy(srcFile, snap)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to copy snapshot to temporary file: %v\", err)\n\t}\n\n\treturn srcFile.Sync()\n}\n","sourceCodeStart":86,"sourceCodeEnd":109,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/raftutil/snapshot.go#L86-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Free disk space (or point the temp file at a volume with room for a full snapshot copy) and retry.","Verify srcFile is opened read-write and still valid before the copy.","Discard/truncate the partially written file after this error; do not treat it as a usable snapshot.","Check the embedded error for ENOSPC vs read-side failures to target the right fix."],"exampleFix":"// before\n_, err = io.Copy(srcFile, snap)\nif err != nil {\n    return fmt.Errorf(\"Failed to copy snapshot to temporary file: %v\", err)\n}\n\n// after\n_, err = io.Copy(srcFile, snap)\nif err != nil {\n    srcFile.Truncate(0)\n    return fmt.Errorf(\"Failed to copy snapshot to temporary file: %v\", err)\n}","handlingStrategy":"validation","validationCode":"func ensureWritableSpace(f *os.File, need uint64) error {\n    // check the file is writable\n    if err := syscall.Faccessat(int(f.Fd()), \"\", unix.W_OK, 0); err != nil {\n        return err\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := raftutil.RedactSnapshot(f); err != nil {\n    if strings.Contains(err.Error(), \"Failed to copy snapshot to temporary file\") {\n        // do not trust partial output\n        f.Truncate(0)\n        log.Printf(\"copy failed: %v — check ENOSPC and file writability\", err)\n    }\n}","preventionTips":["Monitor free space on the volume holding the temp file; snapshots can be gigabytes.","Open the temp file O_RDWR and confirm writability before redaction.","Discard partially written output files after any copy failure.","Prefer temp dirs on the same healthy filesystem as the data."],"tags":["raft","snapshot","io","enospc","go"],"backgroundTag":"no-space-left-on-device","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}