{"record":{"id":"d5172d3fe2e78372","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-uint64-w","errorCode":null,"errorMessage":"cannot read uint64: %w","messagePattern":"cannot read uint64: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vmselectapi/server.go","lineNumber":339,"sourceCode":"func (ctx *vmselectRequestCtx) readUint32() (uint32, error) {\n\tctx.sizeBuf = bytesutil.ResizeNoCopyMayOverallocate(ctx.sizeBuf, 4)\n\tif _, err := io.ReadFull(ctx.bc, ctx.sizeBuf); err != nil {\n\t\tif err == io.EOF {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn 0, fmt.Errorf(\"cannot read uint32: %w\", err)\n\t}\n\tn := encoding.UnmarshalUint32(ctx.sizeBuf)\n\treturn n, nil\n}\n\nfunc (ctx *vmselectRequestCtx) readUint64() (uint64, error) {\n\tctx.sizeBuf = bytesutil.ResizeNoCopyMayOverallocate(ctx.sizeBuf, 8)\n\tif _, err := io.ReadFull(ctx.bc, ctx.sizeBuf); err != nil {\n\t\tif err == io.EOF {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn 0, fmt.Errorf(\"cannot read uint64: %w\", err)\n\t}\n\tn := encoding.UnmarshalUint64(ctx.sizeBuf)\n\treturn n, nil\n}\n\nfunc (ctx *vmselectRequestCtx) readInt64() (int64, error) {\n\tctx.sizeBuf = bytesutil.ResizeNoCopyMayOverallocate(ctx.sizeBuf, 8)\n\tif _, err := io.ReadFull(ctx.bc, ctx.sizeBuf); err != nil {\n\t\tif err == io.EOF {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn 0, fmt.Errorf(\"cannot read int64: %w\", err)\n\t}\n\tn := encoding.UnmarshalInt64(ctx.sizeBuf)\n\treturn n, nil\n}\n\nfunc (ctx *vmselectRequestCtx) readAccountIDProjectID() (uint32, uint32, error) {","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/vmselectapi/server.go#L321-L357","documentation":"Returned by vmselectRequestCtx.readUint64 when io.ReadFull cannot read the full 8 bytes of a uint64 field from the vmselect connection and the error is not a clean EOF. The underlying io error is wrapped with %w. Like the uint32 variant, it signals a truncated or broken binary protocol stream (readTimeRange, processRegisterMetricNames callers).","triggerScenarios":"A caller sends fewer than 8 bytes for a time-range / timestamp field read by readTimeRange or processRegisterMetricNames; the connection is reset or times out while reading the 8-byte value.","commonSituations":"Custom clients writing timestamps as 4 bytes instead of 8; half-closed connections where the peer finished early; proxy buffering limits truncating the request; version-skewed cluster nodes.","solutions":["Confirm the client writes uint64 fields as exactly 8 bytes little-endian.","Inspect the wrapped error: unexpected-EOF implies truncated write; reset implies dropped connection.","Align VictoriaMetrics component versions (vmagent/vminsert vs vmselect).","Check idle/read timeouts on load balancers between cluster components.","Retry on a new connection."],"exampleFix":"// before (4-byte timestamp)\nbinary.LittleEndian.PutUint32(buf, uint32(ts))\n// after\nb := make([]byte, 8)\nbinary.LittleEndian.PutUint64(b, uint64(ts))\nconn.Write(b)","handlingStrategy":"try-catch","validationCode":"// client side\nvar v uint64\nbinary.LittleEndian.PutUint64(buf, v) // exactly 8 bytes, never manual append","typeGuard":"func isTruncatedRead(err error) bool { return errors.Is(err, io.ErrUnexpectedEOF) }","tryCatchPattern":"v, err := readUint64(conn)\nif err != nil {\n    if errors.Is(err, io.EOF) { return io.EOF }\n    return fmt.Errorf(\"failed reading uint64 field: %w\", err)\n}","preventionTips":["Use encoding.PutUint64 for all 64-bit fields","Keep client and vmselect versions in lockstep","Monitor connection-reset metrics between cluster nodes","Avoid half-closing connections before the response is read","Test protocol clients against a real vmselect instance"],"tags":["network","io","protocol","tcp"],"backgroundTag":"unexpected-eof-on-socket-read","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}