{"record":{"id":"7b08ca80a73afd8d","repo":"larksuite/cli","slug":"protocol-frame-exceeds-maxframebytes","errorCode":null,"errorMessage":"protocol: frame exceeds MaxFrameBytes","messagePattern":"protocol: frame exceeds MaxFrameBytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/event/adapter/localbus/protocol/codec.go","lineNumber":37,"sourceCode":"// keeps the two in step, since the ingress deliberately does not import this\n// package.\nconst MaxEventPayloadBytes = 1 << 20\n\n// maxFrameOverheadBytes is the room a frame gets on top of its payload for the\n// canonical metadata and JSON punctuation around it. Worst-case realistic\n// metadata measures a few hundred bytes, so this is generous on purpose: a\n// frame limit that merely equalled the payload limit would make the top of the\n// accepted payload range undeliverable, which is how an accepted event turned\n// into a dropped one.\nconst maxFrameOverheadBytes = 4 << 10\n\n// MaxFrameBytes bounds reader buffer growth. It must stay above\n// MaxEventPayloadBytes, or the bus can frame an event the consumer then refuses\n// to read.\nconst MaxFrameBytes = MaxEventPayloadBytes + maxFrameOverheadBytes\n\n// ErrFrameTooLarge is returned by ReadFrame when a single frame exceeds MaxFrameBytes.\nvar ErrFrameTooLarge = errors.New(\"protocol: frame exceeds MaxFrameBytes\")\n\nconst WriteTimeout = 5 * time.Second // bound writes against wedged peer kernel buffer\n\ntype typeEnvelope struct {\n\tType string `json:\"type\"`\n}\n\nfunc Encode(w io.Writer, msg interface{}) error {\n\tdata, err := json.Marshal(msg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"protocol encode: %w\", err)\n\t}\n\tdata = append(data, '\\n')\n\t_, err = w.Write(data)\n\treturn err\n}\n\nfunc EncodeWithDeadline(conn net.Conn, msg interface{}, timeout time.Duration) error {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/event/adapter/localbus/protocol/codec.go#L19-L55","documentation":"ErrFrameTooLarge is returned by ReadFrame when a single frame read from the local bus exceeds MaxFrameBytes (= MaxEventPayloadBytes + overhead). The bound exists so reader buffer growth is capped; the constant deliberately stays above MaxEventPayloadBytes so the bus never frames an event a consumer would then refuse to read. Hitting it means the stream delivered a frame larger than the protocol allows, indicating a corrupted or misbehaving peer.","triggerScenarios":"Reading from a localbus connection where the peer writes a frame larger than MaxFrameBytes (codec.go:73 and :78 both return it when len(buf)+len(chunk) exceeds the cap, including on bufio.ErrBufferFull).","commonSituations":"A producer built against a different/larger payload limit; a corrupted or desynchronized stream misinterpreting payload bytes as a huge length; a foreign process writing to the same socket/pipe.","solutions":["Verify the producer uses the same protocol version and respects MaxEventPayloadBytes","Re-establish the bus connection to resynchronize the stream","Audit for foreign/corrupt writers on the bus transport"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(payload) > protocol.MaxEventPayloadBytes {\n    return fmt.Errorf(\"event payload %d exceeds limit %d\", len(payload), protocol.MaxEventPayloadBytes)\n}","typeGuard":"func isFrameTooLarge(err error) bool { return errors.Is(err, protocol.ErrFrameTooLarge) }","tryCatchPattern":"frame, err := protocol.ReadFrame(r)\nif errors.Is(err, protocol.ErrFrameTooLarge) {\n    // drop connection and resync; peer violated the protocol\n}","preventionTips":["Keep event payloads within MaxEventPayloadBytes","Use matching protocol versions on producer and consumer","Restrict write access to the bus transport to trusted processes","Log and reconnect on any ErrFrameTooLarge instead of continuing a desynced stream"],"tags":["ipc","protocol","localbus"],"backgroundTag":"frame-too-large","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}