{"record":{"id":"affe0ffdb7261c0c","repo":"thanos-io/thanos","slug":"creating-snappy-compressor-w","errorCode":null,"errorMessage":"creating snappy compressor: %w","messagePattern":"creating snappy compressor: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/postings_codec.go","lineNumber":105,"sourceCode":"\t\tret += snappy.MaxEncodedLen(length)\n\t}\n\n\treturn ret\n}\n\nfunc diffVarintSnappyStreamedEncode(p index.Postings, length int) ([]byte, error) {\n\tcompressedBuf := bytes.NewBuffer(make([]byte, 0, estimateSnappyStreamSize(length)))\n\tif n, err := compressedBuf.WriteString(codecHeaderStreamedSnappy); err != nil {\n\t\treturn nil, fmt.Errorf(\"writing streamed snappy header\")\n\t} else if n != len(codecHeaderStreamedSnappy) {\n\t\treturn nil, fmt.Errorf(\"short-write streamed snappy header\")\n\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}","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/postings_codec.go#L87-L123","documentation":"The encoder wraps any error from extsnappy.Compressor.Compress (constructing the snappy stream writer) with this message. It means the snappy compression writer could not be initialized before encoding postings.","triggerScenarios":"encodePostingsToCache -> diffVarintSnappyStreamedEncode when extsnappy.Compressor.Compress(compressedBuf) returns an error (e.g., failure setting up the streaming compressor).","commonSituations":"Faulty or misconfigured external snappy compressor build (extsnappy is a vendored Prometheus snappy wrapper); resource exhaustion during writer setup.","solutions":["Check the underlying wrapped error (%w) for the root cause","Verify the snappy dependency (github.com/golang/snappy / extsnappy) builds correctly in your binary","Retry the encoding; this is typically transient"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure the compressor is initialized once and healthy at startup\nif extsnappy.Compressor == nil {\n    return errors.New(\"snappy compressor not initialized\")\n}","typeGuard":null,"tryCatchPattern":"b, err := diffVarintSnappyStreamedEncode(p, length)\nif err != nil {\n    var wrapped *fmt.wrapError\n    if errors.As(err, &wrapped) && strings.Contains(err.Error(), \"creating snappy compressor\") {\n        return retryEncoder(p, length) // retry after transient failure\n    }\n    return nil, err\n}","preventionTips":["Log the wrapped inner error, not just the wrapper message","Verify snappy dependency integrity in the build (vendored extsnappy)","Retry transient compressor initialization failures"],"tags":["snappy","compression","encoding"],"backgroundTag":"internal-invariant-violation","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"}