{"record":{"id":"029baebf2947affc","repo":"hashicorp/nomad","slug":"failed-to-write-snapshot-metadata-v","errorCode":null,"errorMessage":"failed to write snapshot metadata: %v","messagePattern":"failed to write snapshot metadata: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/snapshot/archive.go","lineNumber":127,"sourceCode":"\n\t// Encode the snapshot metadata, which we need to feed back during a\n\t// restore.\n\tmetaHash := hl.Add(\"meta.json\")\n\tvar metaBuffer bytes.Buffer\n\tenc := json.NewEncoder(&metaBuffer)\n\tif err := enc.Encode(metadata); err != nil {\n\t\treturn fmt.Errorf(\"failed to encode snapshot metadata: %v\", err)\n\t}\n\tif err := archive.WriteHeader(&tar.Header{\n\t\tName:    \"meta.json\",\n\t\tMode:    0600,\n\t\tSize:    int64(metaBuffer.Len()),\n\t\tModTime: now,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot metadata header: %v\", err)\n\t}\n\tif _, err := io.Copy(archive, io.TeeReader(&metaBuffer, metaHash)); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot metadata: %v\", err)\n\t}\n\n\t// Copy the snapshot data given the size from the metadata.\n\tsnapHash := hl.Add(\"state.bin\")\n\tif err := archive.WriteHeader(&tar.Header{\n\t\tName:    \"state.bin\",\n\t\tMode:    0600,\n\t\tSize:    metadata.Size,\n\t\tModTime: now,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot data header: %v\", err)\n\t}\n\tif _, err := io.CopyN(archive, io.TeeReader(snap, snapHash), metadata.Size); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot metadata: %v\", err)\n\t}\n\n\t// Create a SHA256SUMS file that we can use to verify on restore.\n\tvar shaBuffer bytes.Buffer","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/snapshot/archive.go#L109-L145","documentation":"After writing the meta.json header, write() copies the JSON bytes into the tar via io.Copy with a TeeReader feeding the metadata hash. This error wraps a copy failure while writing meta.json contents. Note the message says 'metadata' and refers to the meta.json body, not its header.","triggerScenarios":"io.Copy(archive, io.TeeReader(&metaBuffer, metaHash)) fails because the underlying writer errors mid-write: disk full, connection reset, or writer closed.","commonSituations":"Destination disk fills during snapshot creation; network sink drops mid-stream.","solutions":["Free disk space or redirect the snapshot to storage with capacity for meta.json plus metadata.Size bytes","Retry the snapshot write after confirming the destination is writable","Read the wrapped error for the concrete cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"free, _ := diskFree(destPath)\nif free < metadata.Size+1<<20 {\n    return errors.New(\"insufficient space for snapshot\")\n}","typeGuard":null,"tryCatchPattern":"if err := write(archive, metadata, snap); err != nil {\n    if strings.Contains(err.Error(), \"failed to write snapshot metadata: \") && !errors.Is(err, io.EOF) {\n        return fmt.Errorf(\"snapshot write failed: %w\", err)\n    }\n    return err\n}","preventionTips":["Provision headroom larger than metadata.Size","Retry snapshot creation on transient sink errors","Monitor disk usage on snapshot targets"],"tags":["tar","io","disk"],"backgroundTag":"disk-full","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"}