{"record":{"id":"bc5441c73fb0b726","repo":"nats-io/nats-server","slug":"metadata-incomplete","errorCode":null,"errorMessage":"metadata incomplete","messagePattern":"metadata incomplete","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":14494,"sourceCode":"\tb[3] = byte(c.Algorithm)\n\tn := binary.PutUvarint(b[4:], c.OriginalSize)\n\treturn b[:4+n]\n}\n\nfunc (c *CompressionInfo) UnmarshalMetadata(b []byte) (int, error) {\n\tc.Algorithm = NoCompression\n\tc.OriginalSize = 0\n\tif len(b) < 5 { // 4 + min 1 for uvarint uint64\n\t\treturn 0, nil\n\t}\n\tif b[0] != 'c' || b[1] != 'm' || b[2] != 'p' {\n\t\treturn 0, nil\n\t}\n\tvar n int\n\tc.Algorithm = StoreCompression(b[3])\n\tc.OriginalSize, n = binary.Uvarint(b[4:])\n\tif n <= 0 {\n\t\treturn 0, fmt.Errorf(\"metadata incomplete\")\n\t}\n\treturn 4 + n, nil\n}\n\nfunc (alg StoreCompression) Compress(buf []byte) ([]byte, error) {\n\tif len(buf) < checksumSize {\n\t\treturn nil, fmt.Errorf(\"uncompressed buffer is too short\")\n\t}\n\tbodyLen := int64(len(buf) - checksumSize)\n\tvar output bytes.Buffer\n\tvar writer io.WriteCloser\n\tswitch alg {\n\tcase NoCompression:\n\t\treturn buf, nil\n\tcase S2Compression:\n\t\twriter = s2.NewWriter(&output)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"compression algorithm not known\")","sourceCodeStart":14476,"sourceCodeEnd":14512,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L14476-L14512","documentation":"When decoding compression metadata for a stored block, the parser reads the algorithm byte and then a Uvarint original size. If binary.Uvarint returns n <= 0 (buffer truncated or malformed varint), there is not enough valid metadata to proceed, so it returns \"metadata incomplete\". From server/filestore.go's compression header decode path.","triggerScenarios":"Decoding a compressed block whose bytes are truncated (short read from disk) or whose metadata region is corrupted so the varint size field is missing/malformed.","commonSituations":"Disk corruption or partial write of a JetStream block; truncating a store file manually; restoring an incomplete backup; reading past EOF on a damaged file.","solutions":["Treat the block as corrupt and rebuild/consume the data from replicated peers or backups","Verify disk integrity (fsck, SMART) if this recurs on the same volume","Restore JetStream data from a verified backup taken with the server stopped","Delete the corrupt consumer block and let the consumer state be recreated (redelivery handles the gap)"],"exampleFix":"null","handlingStrategy":"type-guard","validationCode":"func blockMetadataLooksSane(b []byte) bool {\n\tif len(b) < 4 { return false }\n\t_, n := binary.Uvarint(b[4:])\n\treturn n > 0\n}","typeGuard":"func hasCompleteMetadata(b []byte) bool {\n\tif len(b) < 5 { return false }\n\t_, n := binary.Uvarint(b[4:])\n\treturn n > 0\n}","tryCatchPattern":"size, err := decodeCompressionMeta(b)\nif err != nil && strings.Contains(err.Error(), \"metadata incomplete\") {\n\t// mark block corrupt, recover from replica/backup\n\treturn errBlockCorrupt\n}","preventionTips":["Stop the server before copying or restoring JetStream files","Monitor disks for corruption; use replicas for state","Never truncate store files manually","Verify backups (checksums) before restoring"],"tags":["jetstream","filestore","compression","corruption"],"backgroundTag":"corrupt-block-metadata","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}