{"record":{"id":"34930e81140eb7c5","repo":"micro/go-micro","slug":"grpc-received-message-larger-than-max-d-vs-d","errorCode":null,"errorMessage":"grpc: received message larger than max (%d vs. %d)","messagePattern":"grpc: received message larger than max \\((.+?) vs\\. (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"codec/grpc/util.go","lineNumber":38,"sourceCode":"\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 {\n\theader := make([]byte, 5)\n\n\t// set compression","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/codec/grpc/util.go#L20-L56","documentation":"The gRPC codec enforces MaxMessageSize when decoding a length-prefixed frame: if the declared message length exceeds MaxMessageSize, decode aborts with this error before allocating the buffer. The two values printed are the received length and the configured max.","triggerScenarios":"Server or client sends a message whose wire length exceeds codec.MaxMessageSize (default small, e.g. 8192 bytes in this codec) while reading a response or request body via ReadBody.","commonSituations":"Large RPC payloads (big files, bulk exports) exceeding the small default; one side configured with a larger max than the other; proxies buffering responses larger than the client's limit.","solutions":["Increase MaxMessageSize on the codec for both client and server (micro codec options).","Chunk large payloads into smaller messages.","Compress payloads before sending.","Confirm both sides agree on the same MaxMessageSize configuration."],"exampleFix":"// before\nc := grpc.NewCodec()\n// after\nc := grpc.NewCodec(codec.MaxMessageSize(1024 * 1024 * 16)) // 16MB","handlingStrategy":"validation","validationCode":"// Enforce a client-side size limit before sending:\nif len(payload) > maxAllowed {\n\treturn fmt.Errorf(\"payload %d exceeds codec max %d; chunk or raise MaxMessageSize\", len(payload), maxAllowed)\n}","typeGuard":null,"tryCatchPattern":"if err := client.Call(ctx, req, resp); err != nil {\n\tif strings.Contains(err.Error(), \"grpc: received message larger than max\") {\n\t\t// raise codec.MaxMessageSize on both sides or chunk the payload\n\t}\n\treturn err\n}","preventionTips":["Set codec.MaxMessageSize explicitly and identically on client and server.","Chunk or compress payloads expected to exceed the default.","Add payload-size assertions in tests for large-message endpoints.","Check proxy/gateway body-size limits as well."],"tags":["grpc","codec","message-size"],"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"}