{"record":{"id":"ae9d8393c4b90eed","repo":"t8y2/dbx","slug":"invalid-rocketmq-frame-length-d","errorCode":null,"errorMessage":"invalid RocketMQ frame length: %d","messagePattern":"invalid RocketMQ frame length: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rocketmq/routing.go","lineNumber":249,"sourceCode":"\t\t}\n\t\tencoded, err := command.Encode()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif _, err := destination.Write(encoded); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n}\n\nfunc readRemotingFrame(reader io.Reader) ([]byte, error) {\n\theader := make([]byte, 4)\n\tif _, err := io.ReadFull(reader, header); err != nil {\n\t\treturn nil, err\n\t}\n\tlength := int(binary.BigEndian.Uint32(header))\n\tif length <= 0 || length > 64*1024*1024 {\n\t\treturn nil, fmt.Errorf(\"invalid RocketMQ frame length: %d\", length)\n\t}\n\tframe := make([]byte, 4+length)\n\tcopy(frame, header)\n\tif _, err := io.ReadFull(reader, frame[4:]); err != nil {\n\t\treturn nil, err\n\t}\n\treturn frame, nil\n}\n\nfunc signCommand(command *remoting.RemotingCommand, accessKey, secretKey string) {\n\tif accessKey == \"\" && secretKey == \"\" {\n\t\treturn\n\t}\n\tif command.ExtFields == nil {\n\t\tcommand.ExtFields = map[string]string{}\n\t}\n\tdelete(command.ExtFields, \"Signature\")\n\tcommand.ExtFields[\"AccessKey\"] = accessKey","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rocketmq/routing.go#L231-L267","documentation":"readRemotingFrame reads the 4-byte big-endian length prefix of a RocketMQ remoting frame and rejects any length that is non-positive or exceeds the 64MiB safety cap. This guard prevents allocating huge buffers from corrupt, truncated, or non-RocketMQ streams. It indicates the connection is not delivering a valid RocketMQ remoting protocol stream.","triggerScenarios":"Calling forward/readRemotingFrame against a socket whose stream is not a RocketMQ remoting response: garbage bytes, a truncated/corrupted header, an intermediate proxy speaking a different protocol, or a length field exceeding 64*1024*1024.","commonSituations":"Pointing the driver at the wrong port (e.g. HTTP/health endpoint instead of the remoting port 9876); a firewall or LB mangling the stream; reading from a TLS-wrapped connection without TLS setup; broker protocol/version mismatch.","solutions":["Verify the configured broker address and port actually serve the RocketMQ remoting protocol (default 9876/10911), not an HTTP or console endpoint","Check for TLS/proxy interference: connect directly to the broker to see if the error disappears","Capture the first bytes of the stream (tcpdump/wireshark) to confirm a plausible length prefix","Upgrade/align driver and broker versions to ensure remoting protocol compatibility"],"exampleFix":"// before\naddr := \"localhost:8080\" // console/HTTP port\nclient := admin.New(addr)\n// after\naddr := \"localhost:9876\" // broker remoting port\nclient := admin.New(addr)","handlingStrategy":"validation","validationCode":"// ensure addr points at the remoting port before connecting\nu, err := net.ResolveTCPAddr(\"tcp\", brokerAddr)\nif err != nil || u.Port == 80 || u.Port == 8080 {\n    return fmt.Errorf(\"brokerAddr %q does not look like a remoting endpoint\", brokerAddr)\n}","typeGuard":null,"tryCatchPattern":"frame, err := readRemotingFrame(conn)\nif err != nil {\n    var protoErr *protocolError\n    if errors.As(err, &protoErr) && strings.Contains(protoErr.Error(), \"invalid RocketMQ frame length\") {\n        // reconnect to correct broker endpoint / reset stream\n    }\n    return err\n}","preventionTips":["Use the broker remoting port (default 9876/10911), never console or HTTP ports","Connect directly to brokers in dev to rule out TLS/proxy mangling","Cap message sizes well under 64MiB so responses never approach the limit","Pin driver and broker versions known to interoperate"],"tags":["network","protocol","rocketmq","frame-length"],"backgroundTag":"invalid-frame-length","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}