{"record":{"id":"05d46bf9e8ef138c","repo":"nats-io/nats-server","slug":"failed-to-decompress-original-block-w","errorCode":null,"errorMessage":"failed to decompress original block: %w","messagePattern":"failed to decompress original block: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":7998,"sourceCode":"\tmeta := &CompressionInfo{}\n\tif _, err := meta.UnmarshalMetadata(origBuf); err != nil {\n\t\t// An error is only returned here if there's a problem with parsing\n\t\t// the metadata. If the file has no metadata at all, no error is\n\t\t// returned and the algorithm defaults to no compression.\n\t\treturn fmt.Errorf(\"failed to read existing metadata header: %w\", err)\n\t}\n\tif meta.Algorithm == alg {\n\t\t// The block is already compressed with the chosen algorithm so there\n\t\t// is nothing else to do. This is not a common case, it is here only\n\t\t// to ensure we don't do unnecessary work in case something asked us\n\t\t// to recompress an already compressed block with the same algorithm.\n\t\treturn nil\n\t} else if alg != NoCompression {\n\t\t// The block is already compressed using some algorithm, so we need\n\t\t// to decompress the block using the existing algorithm before we can\n\t\t// recompress it with the new one.\n\t\tif origBuf, err = meta.Algorithm.Decompress(origBuf); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to decompress original block: %w\", err)\n\t\t}\n\t}\n\n\treturn mb.atomicOverwriteFile(origBuf, true)\n}\n\n// Lock should be held.\nfunc (mb *msgBlock) atomicOverwriteFile(buf []byte, allowCompress bool) error {\n\tif mb.mfd != nil {\n\t\tmb.closeFDsLockedNoCheck()\n\t\tdefer mb.enableForWriting(mb.fs.fip)\n\t}\n\n\torigFN := mb.mfn               // The original message block on disk.\n\ttmpFN := mb.mfn + blkTmpSuffix // The new block will be written here.\n\n\t// Rather than modifying the existing block on disk (which is a dangerous\n\t// operation if something goes wrong), create a new temporary file. We will","sourceCodeStart":7980,"sourceCodeEnd":8016,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L7980-L8016","documentation":"Returned during block recompression when decompressing an already-compressed block with its existing algorithm fails. The block claims a compression algorithm in its metadata but its payload cannot be decompressed, so it cannot be re-encoded to the new algorithm.","triggerScenarios":"RecompressMsgBlock switching algorithms (e.g. s2 -> zstd) on a block whose compressed payload is corrupt — interrupted earlier compression, truncated file, or bit rot.","commonSituations":"Server crash mid-compress leaving a half-written block; disk corruption; a block compressed with an algorithm the running binary doesn't support (build flags/version).","solutions":["Check the wrapped cause to identify which algorithm failed to decompress","Verify the running NATS build supports the block's compression algorithm (upgrade if needed)","Restore the block file from backup and retry the algorithm change","If the block is unrecoverable, remove its files and resync/repopulate the stream"],"exampleFix":"// broken block compressed with unsupported algorithm\nnats-server -v\n// upgrade to a build with s2/zstd support, restore block from backup, then:\nnats stream update ORDERS --compression=s2","handlingStrategy":"fallback","validationCode":"// Go: confirm target algorithm is supported by this build before switching\nif !supportedCompression(alg) {\n    return fmt.Errorf(\"build lacks %s support; pick s2 or none\", alg)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to decompress original block\") {\n    log.Printf(\"block corrupt for recompression: %v\", err)\n    return restoreBlockFromBackup(blockPath) // fallback path\n}","preventionTips":["Avoid killing the server mid-compression; watch for compression operations before restarts","Upgrade to builds that support all deployed compression algorithms before switching","Detect corruption early with periodic `nats stream check`/report tooling","Maintain stream backups as the fallback source of truth"],"tags":["jetstream","filestore","compression","decompress-failed","data-corruption"],"backgroundTag":"decompress-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}