{"record":{"id":"7dcee1fce4db9fae","repo":"micro/go-micro","slug":"grpc-received-message-larger-than-max-length-allo","errorCode":null,"errorMessage":"grpc: received message larger than max length allowed on current machine (%d vs. %d)","messagePattern":"grpc: received message larger than max length allowed on current machine \\((.+?) vs\\. (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"codec/grpc/util.go","lineNumber":35,"sourceCode":"\t// read the header\n\tif _, err := r.Read(header); err != nil {\n\t\treturn uint8(0), nil, err\n\t}\n\n\t// get encoding format e.g compressed\n\tcf := header[0]\n\n\t// get message length\n\tlength := binary.BigEndian.Uint32(header[1:])\n\n\t// no encoding format\n\tif length == 0 {\n\t\treturn cf, nil, nil\n\t}\n\n\t//\n\tif int64(length) > int64(maxInt) {\n\t\treturn cf, nil, fmt.Errorf(\"grpc: received message larger than max length allowed on current machine (%d vs. %d)\", length, maxInt)\n\t}\n\tif int(length) > MaxMessageSize {\n\t\treturn cf, nil, fmt.Errorf(\"grpc: received message larger than max (%d vs. %d)\", length, MaxMessageSize)\n\t}\n\n\tmsg := make([]byte, int(length))\n\n\tif _, err := r.Read(msg); err != nil {\n\t\tif err == io.EOF {\n\t\t\terr = io.ErrUnexpectedEOF\n\t\t}\n\t\treturn cf, nil, err\n\t}\n\n\treturn cf, msg, nil\n}\n\nfunc encode(cf uint8, buf []byte, w io.Writer) error {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/codec/grpc/util.go#L17-L53","documentation":"The gRPC codec's decode function reads a 4-byte length-prefixed frame and validates the declared length before allocating. If the declared message length exceeds the maximum representable int on the current platform (int64(length) > int64(maxInt), i.e. a corrupt or malicious prefix on a 32-bit platform), this error is returned instead of attempting a doomed allocation.","triggerScenarios":"Receiving a gRPC frame whose 4-byte big-endian length prefix decodes to a value larger than the platform's max int (int overflow guard); essentially always means a corrupt stream or a non-gRPC peer on the wire.","commonSituations":"Connecting a client to a server that speaks a different framing protocol; truncated/garbled TLS or proxy responses being parsed as gRPC frames; bit corruption or desynced stream after an earlier partial read.","solutions":["Verify both peers use the same protocol/framing (real gRPC vs this codec).","Check for proxies/middlewares corrupting or re-chunking the response stream.","Reset the connection after desync; the stream is unrecoverable.","On 32-bit platforms, prefer exchanging messages whose lengths fit comfortably in int; upgrade to 64-bit if huge payloads are legitimate."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before reading, cap expected sizes in application logic:\nconst maxExpected = 1 << 30\n// ensure the peer is a real gRPC-framed endpoint before interpreting bytes as frames","typeGuard":null,"tryCatchPattern":"cf, buf, err := decode(r)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"grpc: received message larger than max length allowed\") {\n\t\t// corrupt frame / protocol desync: close and reconnect\n\t}\n\treturn err\n}","preventionTips":["Treat this as a protocol violation: reconnect rather than retrying the same stream.","Verify proxies/TLS terminators preserve the gRPC length-prefixed framing.","Confirm both endpoints speak the same transport.","Monitor for this error as a signal of stream desync or a hostile/misconfigured peer."],"tags":["grpc","codec","message-size","protocol"],"backgroundTag":"grpc-message-too-large","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}