VictoriaMetrics/VictoriaMetrics · error

cannot read next field in Dogsketch message: %w

Error message

cannot read next field in Dogsketch message: %w

What it means

Returned by Dogsketch.unmarshalProtobuf when easyproto's NextField cannot parse the next field header inside a Dogsketch submessage — the bytes are not a valid protobuf field stream (truncated tag, invalid varint, or length overrun). It is wrapped up the chain as 'cannot unmarshal Sketch: cannot unmarshal Dogsketch: %w'.

Source

Thrown at lib/protoparser/datadogsketches/parser.go:264

	K   []int32
	N   []uint32
}

// unmarshalProtobuf decodes src to Dogsketch struct
func (d *Dogsketch) unmarshalProtobuf(src []byte) (err error) {
	d.Ts = 0
	d.Cnt = 0
	d.Min = 0.0
	d.Max = 0.0
	d.Sum = 0.0
	d.K = nil
	d.N = nil

	var fc easyproto.FieldContext
	for len(src) > 0 {
		src, err = fc.NextField(src)
		if err != nil {
			return fmt.Errorf("cannot read next field in Dogsketch message: %w", err)
		}
		switch fc.FieldNum {
		case 1:
			ts, ok := fc.Int64()
			if !ok {
				return fmt.Errorf("cannot read timestamp")
			}
			d.Ts = ts
		case 2:
			cnt, ok := fc.Int64()
			if !ok {
				return fmt.Errorf("cannot read count")
			}
			d.Cnt = cnt
		case 3:
			v, ok := fc.Double()
			if !ok {
				return fmt.Errorf("cannot read min")

View on GitHub (pinned to 5079fb58f1)

Solutions

  1. Check for truncation: compare received byte count with the declared Content-Length / message size.
  2. Decode the failing submessage with protoc --decode_raw to locate the malformed header.
  3. Upgrade/align producer and parser on the same agent-payload Dogsketch schema.
  4. Handle as a bad request at the ingestion layer and drop the payload.
Defensive patterns

Strategy: validation

Validate before calling

// verify declared submessage length fits in the buffer before parsing
func fits(b []byte, declared int) bool { return declared >= 0 && declared <= len(b) }

Try / catch

if err := sp.UnmarshalProtobuf(buf); err != nil {
    if strings.Contains(err.Error(), "cannot read next field in Dogsketch") {
        log.Printf("truncated/corrupt dogsketch, dropping payload: %v", err)
        http.Error(w, "malformed sketch payload", http.StatusBadRequest)
        return
    }
    return err
}

Prevention

When it happens

Trigger: The Dogsketch submessage length prefix overstates the available bytes or its content contains an invalid field key — typically truncation or non-protobuf garbage in field-7 data of a Sketch.

Common situations: Payload truncation at a proxy/buffer boundary; producers writing partial sketches after a crash; fuzz testing ingestion endpoints that accept /api/beta/sketches payloads.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03). Data as JSON: /api/errors/c1227cddff3ad92b. Report an issue: GitHub.