{"record":{"id":"1790d4ed7b41afe8","repo":"txthinking/brook","slug":"quic-max-datagram-size-is-1197","errorCode":null,"errorMessage":"quic max datagram size is 1197","messagePattern":"quic max datagram size is 1197","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quicclient.go","lineNumber":146,"sourceCode":"\t\t}\n\t\tif err := sc.Exchange(c); err != nil {\n\t\t\treturn nil\n\t\t}\n\t\treturn nil\n\t}\n\tif r.Cmd == socks5.CmdUDP {\n\t\t_, err := r.UDP(c, x.Server.ServerAddr)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn nil\n\t}\n\treturn socks5.ErrUnsupportCmd\n}\n\nfunc (x *QUICClient) UDPHandle(s *socks5.Server, addr *net.UDPAddr, d *socks5.Datagram) error {\n\tif 12+4+1+len(d.DstAddr)+2+len(d.Data)+16 > 1197 {\n\t\treturn errors.New(\"quic max datagram size is 1197\")\n\t}\n\tdstb := append(append([]byte{d.Atyp}, d.DstAddr...), d.DstPort...)\n\tconn, err := x.PacketConnFactory.Handle(addr, dstb, d.Data, func(b []byte) (int, error) {\n\t\td.Data = b\n\t\treturn s.UDPConn.WriteToUDP(d.Bytes(), addr)\n\t}, x.UDPTimeout)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif conn == nil {\n\t\treturn nil\n\t}\n\tdefer conn.Close()\n\tsa := x.ServerAddress\n\tif sa == \"\" {\n\t\tsa = x.ServerHost\n\t}\n\trc, err := QUICDialUDP(addr.String(), d.Address(), sa, x.TLSConfig, x.UDPTimeout)","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/txthinking/brook/blob/5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8/quicclient.go#L128-L164","documentation":"QUICClient.UDPHandle enforces a maximum QUIC datagram payload size of 1197 bytes. The check 12+4+1+len(DstAddr)+2+len(Data)+16 counts the QUIC packet header, the SOCKS address block (ATyp + address + port), the datagram payload, and the AEAD overhead (16 bytes). If the client's datagram (address + payload) would exceed this QUIC datagram ceiling, the relay is rejected before any packet is sent.","triggerScenarios":"Calling QUICClient.UDPHandle (via the socks5 server UDP path) with a Datagram whose DstAddr plus Data length exceeds 1197 - 34 bytes of fixed overhead, i.e. a payload over roughly 1163 bytes minus address length (long IPv6/hostname targets shrink the usable payload further).","commonSituations":"Clients sending large UDP payloads through the QUIC transport, e.g. DNS responses with large answers, a UDP datagram close to the 1500-byte Ethernet MTU, or apps ignoring QUIC's smaller effective MTU compared to plain UDP forwarding.","solutions":["Reduce the outgoing UDP datagram payload size to fit: keep len(DstAddr) + len(Data) below 1197 - 34 bytes (about 1163 bytes minus address bytes).","For DNS traffic, prefer TCP or DNS-over-HTTPS for responses exceeding the limit, or enable EDNS truncation so resolvers send TC=1 instead of oversized UDP answers.","If the tunnel must carry large datagrams, switch the transport to a stream-based protocol (e.g. the TCP/TLS client) instead of QUIC datagrams."],"exampleFix":"// before\nd.Data = bigPayload // e.g. 1300 bytes\nclient.UDPHandle(server, addr, d) // panics back with \"quic max datagram size is 1197\"\n\n// after\nconst maxQuicDatagram = 1197 - 34 - len(d.DstAddr) // overhead + address\nif len(d.Data) > maxQuicDatagram {\n    d.Data = d.Data[:maxQuicDatagram] // or fragment / use TCP transport\n}","handlingStrategy":"validation","validationCode":"const maxQuicPayload = 1197 - 12 - 4 - 1 - 2 - 16 // 1162 minus address bytes\nfunc fitsQuicDatagram(dstAddr, data []byte) bool {\n    return 12+4+1+len(dstAddr)+2+len(data)+16 <= 1197\n}","typeGuard":null,"tryCatchPattern":"// Go: inspect the error from UDPHandle\nif err := client.UDPHandle(srv, addr, d); err != nil && strings.Contains(err.Error(), \"max datagram size\") {\n    // fall back to TCP transport or fragment the payload\n}","preventionTips":["Cap outbound UDP payloads through QUIC at ~1160 bytes minus address length.","Prefer TCP transport for traffic that can exceed the QUIC datagram limit (large DNS, video, QUIC-in-QUIC).","Enable EDNS0 truncation so oversized DNS replies come via TCP."],"tags":["network","quic","udp","datagram-size"],"backgroundTag":"payload-too-large","analyzedSha":"5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8","analyzedAt":"2026-09-06T04:35:00.432Z","contentChangedAt":"2026-09-06T04:35:00.432Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}