{"record":{"id":"f05f2552e66d6c4a","repo":"n0-computer/iroh","slug":"exceedsmaxpacketsize","errorCode":"ExceedsMaxPacketSize","errorMessage":"Exceeds max packet size ({MAX_PACKET_SIZE}): {size}","messagePattern":"Exceeds max packet size \\((.+?)\\): (.+?)","errorType":"validation","errorClass":"SendError","httpStatus":null,"severity":"error","filePath":"iroh-relay/src/client/conn.rs","lineNumber":149,"sourceCode":"                    RelayToClientMsg::from_bytes(msg, &self.key_cache, self.protocol_version);\n                Poll::Ready(Some(message.map_err(Into::into)))\n            }\n            Some(Err(e)) => Poll::Ready(Some(Err(anyerr!(e).into()))),\n            None => Poll::Ready(None),\n        }\n    }\n}\n\nimpl Sink<ClientToRelayMsg> for Conn {\n    type Error = SendError;\n\n    fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {\n        Pin::new(&mut self.conn).poll_ready(cx).map_err(Into::into)\n    }\n\n    fn start_send(mut self: Pin<&mut Self>, frame: ClientToRelayMsg) -> Result<(), Self::Error> {\n        let size = frame.encoded_len();\n        ensure!(\n            size <= MAX_PACKET_SIZE,\n            SendError::ExceedsMaxPacketSize { size }\n        );\n        if let ClientToRelayMsg::Datagrams { datagrams, .. } = &frame {\n            ensure!(!datagrams.contents.is_empty(), SendError::EmptyPacket);\n        }\n\n        Pin::new(&mut self.conn)\n            .start_send(frame.to_bytes().freeze())\n            .map_err(Into::into)\n    }\n\n    fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {\n        Pin::new(&mut self.conn).poll_flush(cx).map_err(Into::into)\n    }\n\n    fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {\n        Pin::new(&mut self.conn).poll_close(cx).map_err(Into::into)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/n0-computer/iroh/blob/2b4de030ce5e0133f272871a76f0c685c63f552a/iroh-relay/src/client/conn.rs#L131-L167","documentation":"This SendError variant is raised by the relay client connection's Sink::start_send when a ClientToRelayMsg serializes to more than MAX_PACKET_SIZE bytes. The relay protocol enforces a fixed per-packet size limit, so oversized frames are rejected client-side before being written to the connection. It guards against wasted bandwidth and relay-side rejection.","triggerScenarios":"Calling send on a RelayClient connection with a Datagrams message whose accumulated payload encodes to more than MAX_PACKET_SIZE bytes; batching too many/large datagrams into a single ClientToRelayMsg::Datagrams frame.","commonSituations":"Applications stuffing large payloads (e.g. big messages or file chunks) into relay datagrams, or batching code that keeps appending datagrams without checking cumulative encoded size before flushing.","solutions":["Check frame.encoded_len() against MAX_PACKET_SIZE before sending and split or truncate the payload into multiple datagram batches.","Reduce per-datagram payload size so the total encoded frame stays under MAX_PACKET_SIZE.","If large transfers are needed, move the data over a direct connection and use the relay only for hole-punching/control messages."],"exampleFix":"// before\nlet msg = ClientToRelayMsg::Datagrams { .. }; // many datagrams batched\nclient.send(msg).await?;\n\n// after\nif msg.encoded_len() > MAX_PACKET_SIZE {\n    for chunk in split_into_batches(datagrams, MAX_PACKET_SIZE) {\n        client.send(ClientToRelayMsg::Datagrams { datagrams: chunk, .. }).await?;\n    }\n} else {\n    client.send(msg).await?;\n}","handlingStrategy":"validation","validationCode":"fn fits_in_packet(msg: &ClientToRelayMsg) -> bool {\n    msg.encoded_len() <= MAX_PACKET_SIZE\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Batch datagrams with a running encoded_len budget capped at MAX_PACKET_SIZE.","Keep individual datagram payloads well below the limit to leave room for framing.","Use direct connections for large transfers instead of relay datagrams."],"tags":["network","relay","packet-size","iroh"],"backgroundTag":"payload-too-large","analyzedSha":"2b4de030ce5e0133f272871a76f0c685c63f552a","analyzedAt":"2026-09-08T04:26:47.755Z","contentChangedAt":"2026-09-08T04:26:47.755Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}