XTLS/Xray-core · error

failed to read payload length

Error message

failed to read payload length

What it means

Trojan PacketReader.ReadMultiBuffer failed to read the 2-byte UDP payload length after the address. The packet is truncated or the stream desynchronized, so the UDP frame length cannot be determined.

Solutions

  1. Inspect .Base(err) for the read failure
  2. Check MTU/fragmentation on the UDP path
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at proxy/trojan/protocol.go:228 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/deae33f41cedae2f. Report an issue: GitHub.

Appendix: source

Thrown at proxy/trojan/protocol.go:228

	_, err := b.ReadFrom(c)
	return buf.MultiBuffer{b}, err
}

// PacketReader is UDP Connection Reader Wrapper for trojan protocol
type PacketReader struct {
	io.Reader
}

// ReadMultiBuffer implements buf.Reader
func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
	addr, port, err := addrParser.ReadAddressPort(nil, r)
	if err != nil {
		return nil, errors.New("failed to read address and port").Base(err)
	}

	var lengthBuf [2]byte
	if _, err := io.ReadFull(r, lengthBuf[:]); err != nil {
		return nil, errors.New("failed to read payload length").Base(err)
	}

	remain := int(binary.BigEndian.Uint16(lengthBuf[:]))
	if remain > maxLength {
		return nil, errors.New("oversize payload")
	}

	var crlf [2]byte
	if _, err := io.ReadFull(r, crlf[:]); err != nil {
		return nil, errors.New("failed to read crlf").Base(err)
	}

	dest := net.UDPDestination(addr, port)
	var mb buf.MultiBuffer
	for remain > 0 {
		length := buf.Size
		if remain < length {
			length = remain

View on GitHub (pinned to 7d214f8b09)