{"record":{"id":"5e4ca56462e9490c","repo":"thanos-io/thanos","slug":"writing-uvarint-encoded-byte","errorCode":null,"errorMessage":"writing uvarint encoded byte","messagePattern":"writing uvarint encoded byte","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/postings_codec.go","lineNumber":117,"sourceCode":"\t}\n\n\tuvarintEncodeBuf := make([]byte, binary.MaxVarintLen64)\n\n\tsw, err := extsnappy.Compressor.Compress(compressedBuf)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating snappy compressor: %w\", err)\n\t}\n\n\tprev := storage.SeriesRef(0)\n\tfor p.Next() {\n\t\tv := p.At()\n\t\tif v < prev {\n\t\t\treturn nil, errors.Errorf(\"postings entries must be in increasing order, current: %d, previous: %d\", v, prev)\n\t\t}\n\n\t\tuvarintSize := binary.PutUvarint(uvarintEncodeBuf, uint64(v-prev))\n\t\tif written, err := sw.Write(uvarintEncodeBuf[:uvarintSize]); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"writing uvarint encoded byte\")\n\t\t} else if written != uvarintSize {\n\t\t\treturn nil, errors.Wrap(err, \"short-write for uvarint encoded byte\")\n\t\t}\n\n\t\tprev = v\n\t}\n\tif p.Err() != nil {\n\t\treturn nil, p.Err()\n\t}\n\tif err := sw.Close(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"closing snappy stream writer\")\n\t}\n\n\treturn compressedBuf.Bytes(), nil\n}\n\nfunc diffVarintSnappyStreamedDecode(input []byte, disablePooling bool) (closeablePostings, error) {\n\tif !isDiffVarintSnappyStreamedEncodedPostings(input) {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/postings_codec.go#L99-L135","documentation":"The snappy stream writer rejected a Write of a delta-encoded uvarint posting while encoding postings for the cache. The postings themselves are valid; the failure comes from the underlying compression stream (usually its output buffer or I/O), and it aborts the whole postings-encoding pass.","triggerScenarios":"encodePostingsToCache -> diffVarintSnappyStreamedEncode when sw.Write(uvarintEncodeBuf[:uvarintSize]) returns an error, typically the underlying snappy writer hitting an I/O or state failure.","commonSituations":"Memory pressure while the snappy stream flushes; a compressor writer already in an error state.","solutions":["Inspect the wrapped underlying error for the root cause","Retry the encoding operation","Increase available memory if OOM-adjacent"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"b, err := diffVarintSnappyStreamedEncode(p, length)\nif err != nil {\n    if strings.Contains(err.Error(), \"writing uvarint encoded byte\") {\n        log.WithError(errors.Unwrap(err)).Error(\"snappy stream write failed\")\n        return retryEncoder(p, length)\n    }\n    return nil, err\n}","preventionTips":["Inspect the unwrapped error for the true cause","Ensure adequate memory for stream flushing","Retry encoding on transient writer failures"],"tags":["snappy","encoding","write-error"],"backgroundTag":"broken-pipe","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}