{"record":{"id":"7c571f4237985e83","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-int64-w","errorCode":null,"errorMessage":"cannot read int64: %w","messagePattern":"cannot read int64: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vmselectapi/server.go","lineNumber":351,"sourceCode":"func (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) {\n\taccountID, err := ctx.readUint32()\n\tif err != nil {\n\t\treturn 0, 0, fmt.Errorf(\"cannot read accountID: %w\", err)\n\t}\n\tprojectID, err := ctx.readUint32()\n\tif err != nil {\n\t\treturn 0, 0, fmt.Errorf(\"cannot read projectID: %w\", err)\n\t}\n\treturn accountID, projectID, nil\n}\n\n// maxSearchQuerySize is the maximum size of SearchQuery packet in bytes.","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/vmselectapi/server.go#L333-L369","documentation":"Returned by vmselectRequestCtx.readInt64 when io.ReadFull fails to read the full 8 bytes of an int64 field (used by processMetricNamesUsageStats) with a non-EOF error. The cause is wrapped with %w. It means the protocol stream carrying the usage-stats request was truncated or the connection broke.","triggerScenarios":"A client calling the metric-names usage stats endpoint over the internal vmselect protocol sends fewer than 8 bytes for the int64 field, or the connection dies mid-read.","commonSituations":"Hand-written protocol clients mis-sizing fields; network interruption between vminsert/vmagent and vmselect; LB or firewall dropping long-lived internal connections.","solutions":["Verify the int64 field is written as exactly 8 bytes little-endian.","Check the wrapped cause (unexpected EOF vs reset) to distinguish truncation from connection loss.","Match component versions across the cluster.","Inspect LB/firewall idle-timeout settings for internal select connections.","Retry on a fresh connection."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// client side: fixed 8-byte encoding for int64 fields\nbinary.LittleEndian.PutUint64(buf, uint64(int64Val))","typeGuard":"func isTruncatedRead(err error) bool { return errors.Is(err, io.ErrUnexpectedEOF) }","tryCatchPattern":"v, err := readInt64(conn)\nif err != nil {\n    if errors.Is(err, io.EOF) { return io.EOF }\n    return fmt.Errorf(\"failed reading int64 field: %w\", err)\n}","preventionTips":["Round-trip int64 through uint64 for little-endian encoding","Keep cluster component versions aligned","Add read deadlines to detect stalled connections early","Retry usage-stats requests on a new connection"],"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"}