VictoriaMetrics/VictoriaMetrics · error
cannot read count_float
Error message
cannot read count_float
What it means
Field 2 of the Histogram message is sum as double. unmarshalHistogram calls fc.Double(); if the bytes cannot be read as a fixed64 double it returns "cannot read count_float". Note the message text says count_float but the failing field here is the sum (field 3 path shown); the cause is a wrong wire type or corrupt fixed64 bytes.
Source
Thrown at lib/prompb/write_request_unmarshaler.go:261
var err error
var fc easyproto.FieldContext
for len(src) > 0 {
src, err = fc.NextField(src)
if err != nil {
return tss, labelsPool, samplesPool, fmt.Errorf("cannot read next field: %w", err)
}
var ok bool
switch fc.FieldNum {
case 1:
nhctx.countInt, ok = fc.Uint64()
if !ok {
return tss, labelsPool, samplesPool, fmt.Errorf("cannot read count_int")
}
case 2:
nhctx.countFloat, ok = fc.Double()
if !ok {
return tss, labelsPool, samplesPool, fmt.Errorf("cannot read count_float")
}
nhctx.isCountFloat = true
case 3:
nhctx.sum, ok = fc.Double()
if !ok {
return tss, labelsPool, samplesPool, fmt.Errorf("cannot read sum")
}
case 4:
nhctx.schema, ok = fc.Sint32()
if !ok {
return tss, labelsPool, samplesPool, fmt.Errorf("cannot read schema")
}
case 5:
nhctx.zeroThreshold, ok = fc.Double()
if !ok {
return tss, labelsPool, samplesPool, fmt.Errorf("cannot read zero_threshold")
}
case 6:View on GitHub (pinned to 5079fb58f1)
Solutions
- Verify count_float (field 2) and sum (field 3) are both encoded as wire type 1 fixed64 doubles
- Check for truncation — an 8-byte double cut short by a bad length prefix produces exactly this failure
- Regenerate the client from the canonical prompb proto and retest
- Round-trip the payload through a reference decoder (protoc --decode) to locate the malformed field
Example fix
// before: sum encoded as varint hb = protowire.AppendTag(hb, 3, protowire.VarintType) hb = protowire.AppendVarint(hb, uint64(sum)) // after: sum encoded as fixed64 double hb = protowire.AppendTag(hb, 3, protowire.Fixed64Type) hb = protowire.AppendFixed64(hb, math.Float64bits(sum))
Defensive patterns
Strategy: validation
Validate before calling
func validateDoubleField(data []byte) bool {
_, n := protowire.ConsumeFixed64(data)
return n > 0
} Try / catch
if err := unmarshalHistogram(data, tss, lp, sp, labels, fb); err != nil {
if strings.Contains(err.Error(), "cannot read count_float") || strings.Contains(err.Error(), "cannot read sum") {
log.Printf("bad double field in histogram: %v", err)
return errBadHistogramField
}
return err
} Prevention
- Always encode double fields (count_float field 2, sum field 3) as wire type 1 fixed64
- Check length prefixes so 8-byte doubles are never truncated
- Verify payloads with protoc --decode during development of custom serializers
- Keep one source of truth for the proto file shared by all producing services
When it happens
Trigger: UnmarshalProtobuf processes a Histogram whose field 2 (count_float) or field 3 (sum) bytes are not valid 8-byte fixed64 doubles — e.g. count_float encoded as varint, or sum truncated to fewer than 8 bytes.
Common situations: Custom histogram serializers using varints for float fields; truncated messages cutting a double in half; clients built against drifted proto definitions where field numbers shifted.
Related errors
- cannot read native histogram data
- failed to unmarshal native histogram: %w
- cannot read count_int
- cannot read label data
- cannot unmarshal label: %w
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/4fe12d87deab43f5.
Report an issue: GitHub.