thanos-io/thanos · error

proto: wrong wireType =

Error message

proto: wrong wireType = %d for field NumLabelPairs

What it means

Generated gogoproto Unmarshal code for the Statistic message (pkg/status/statuspb/rpc.pb.go:1728) rejects a wire value whose field 2 (NumLabelPairs) uses a wire type other than 0 (varint). This means the bytes being decoded do not match the compiled .proto schema — the wire data and the generated code disagree.

Solutions

  1. Ensure both client and server are built from the same Thanos version so the generated rpc.pb.go and the sender's schema match
  2. Regenerate the statuspb package with the same protoc/gogoproto versions used by the sender
  3. Verify no proxy is rewriting/truncating the gRPC response
  4. Check whether field numbering changed in rpc.proto (NumLabelPairs must be field 2, varint)
  5. Enable gRPC wire-format logging to compare the raw bytes against the expected schema

Example fix

// before: mismatched schemas
client := statuspbv1 // built from old rpc.proto
// after: pin the same generated package
import "github.com/thanos-io/thanos/pkg/status/statuspb"
conn, _ := grpc.Dial(addr, grpc.WithCodec(statuspb.Codec))
Defensive patterns

Strategy: try-catch

Validate before calling

// verify schema compatibility before streaming
if !semverCompatible(peerVersion, minSupportedVersion) {
    return fmt.Errorf("peer %s version %s incompatible for TSDB statistics", peer, peerVersion)
}

Try / catch

if err := proto.Unmarshal(buf, &stat); err != nil {
    if strings.Contains(err.Error(), "wrong wireType") {
        return fmt.Errorf("schema mismatch with peer: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Unmarshaling a TSDBStatistics/Statistic protobuf message where field number 2 arrives as a length-delimited (2), 64-bit (1), or 32-bit (5) type instead of a varint, typically because the sender uses a different schema version.

Common situations: Version mismatch between Thanos components (one built with an older/different rpc.proto); sending raw bytes written by a different generator (gogo vs google.golang.org/protobuf ordering); corrupt or hand-crafted gRPC 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 thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/245f1f5ab7518cab. Report an issue: GitHub.

Appendix: source

Thrown at pkg/status/statuspb/rpc.pb.go:1728

			}
			m.NumSeries = 0
			for shift := uint(0); ; shift += 7 {
				if shift >= 64 {
					return ErrIntOverflowRpc
				}
				if iNdEx >= l {
					return io.ErrUnexpectedEOF
				}
				b := dAtA[iNdEx]
				iNdEx++
				m.NumSeries |= uint64(b&0x7F) << shift
				if b < 0x80 {
					break
				}
			}
		case 2:
			if wireType != 0 {
				return fmt.Errorf("proto: wrong wireType = %d for field NumLabelPairs", wireType)
			}
			m.NumLabelPairs = 0
			for shift := uint(0); ; shift += 7 {
				if shift >= 64 {
					return ErrIntOverflowRpc
				}
				if iNdEx >= l {
					return io.ErrUnexpectedEOF
				}
				b := dAtA[iNdEx]
				iNdEx++
				m.NumLabelPairs |= int64(b&0x7F) << shift
				if b < 0x80 {
					break
				}
			}
		case 3:
			if wireType != 0 {

View on GitHub (pinned to 35b8b99117)