thanos-io/thanos · error

writing uvarint encoded byte

Error message

writing uvarint encoded byte

What it means

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.

Solutions

  1. Inspect the wrapped underlying error for the root cause
  2. Retry the encoding operation
  3. Increase available memory if OOM-adjacent
Defensive patterns

Strategy: try-catch

Try / catch

b, err := diffVarintSnappyStreamedEncode(p, length)
if err != nil {
    if strings.Contains(err.Error(), "writing uvarint encoded byte") {
        log.WithError(errors.Unwrap(err)).Error("snappy stream write failed")
        return retryEncoder(p, length)
    }
    return nil, err
}

Prevention

When it happens

Trigger: encodePostingsToCache -> diffVarintSnappyStreamedEncode when sw.Write(uvarintEncodeBuf[:uvarintSize]) returns an error, typically the underlying snappy writer hitting an I/O or state failure.

Common situations: Memory pressure while the snappy stream flushes; a compressor writer already in an error state.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/5e4ca56462e9490c. Report an issue: GitHub.

Appendix: source

Thrown at pkg/store/postings_codec.go:117

	}

	uvarintEncodeBuf := make([]byte, binary.MaxVarintLen64)

	sw, err := extsnappy.Compressor.Compress(compressedBuf)
	if err != nil {
		return nil, fmt.Errorf("creating snappy compressor: %w", err)
	}

	prev := storage.SeriesRef(0)
	for p.Next() {
		v := p.At()
		if v < prev {
			return nil, errors.Errorf("postings entries must be in increasing order, current: %d, previous: %d", v, prev)
		}

		uvarintSize := binary.PutUvarint(uvarintEncodeBuf, uint64(v-prev))
		if written, err := sw.Write(uvarintEncodeBuf[:uvarintSize]); err != nil {
			return nil, errors.Wrap(err, "writing uvarint encoded byte")
		} else if written != uvarintSize {
			return nil, errors.Wrap(err, "short-write for uvarint encoded byte")
		}

		prev = v
	}
	if p.Err() != nil {
		return nil, p.Err()
	}
	if err := sw.Close(); err != nil {
		return nil, errors.Wrap(err, "closing snappy stream writer")
	}

	return compressedBuf.Bytes(), nil
}

func diffVarintSnappyStreamedDecode(input []byte, disablePooling bool) (closeablePostings, error) {
	if !isDiffVarintSnappyStreamedEncodedPostings(input) {

View on GitHub (pinned to 35b8b99117)