{"record":{"id":"de43385ef792e753","repo":"XTLS/Xray-core","slug":"read-bytes-w","errorCode":null,"errorMessage":"read bytes: %w","messagePattern":"read bytes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/internet/finalmask/xmc/protocol.go","lineNumber":316,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc (v *UUID) writeTo(w io.Writer) error {\n\t_, err := w.Write(v[:])\n\tif err != nil {\n\t\treturn fmt.Errorf(\"write UUID: %w\", err)\n\t}\n\treturn nil\n}\n\ntype Bytes []byte\n\nfunc (v *Bytes) readFrom(r io.Reader) error {\n\tvar length Varint\n\terr := length.readFrom(r)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read bytes: %w\", err)\n\t}\n\n\tif length < 0 || length >= 1024 {\n\t\treturn fmt.Errorf(\"read bytes: invalid size: %d\", length)\n\t}\n\n\tbuf := make([]byte, length)\n\n\t_, err = io.ReadFull(r, buf)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read bytes: %w\", err)\n\t}\n\n\t*v = append([]byte(*v), buf...)\n\n\treturn nil\n}\n","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/transport/internet/finalmask/xmc/protocol.go#L298-L334","documentation":"Bytes.readFrom first reads a Varint length prefix; this message wraps a failure of that Varint read (itself usually 'read varint: %w'). It means the connection failed or ended while the length prefix of a byte-array field was being read — the payload was never reached.","triggerScenarios":"Peer closes or resets the connection between a packet header and a Bytes field; a read deadline expires mid-varint; the stream is desynchronized so the reader is at EOF where a varint should start.","commonSituations":"Server drops the client during login (bad profile, rate limit); half-open connections after network changes; framing desync caused by mismatched padding schedules making the reader consume the wrong bytes.","solutions":["Treat io.EOF / io.ErrUnexpectedEOF on this path as 'peer ended the stream', and RST as abrupt close — log and reconnect.","Confirm both endpoints run compatible padding presets; desync makes later reads fail here.","Set read deadlines so dead peers fail fast instead of hanging before this error.","Reproduce with verbose logging of packet IDs to find which field read failed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := bytesField.readFrom(r); err != nil {\n    if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {\n        return fmt.Errorf(\"peer closed during length prefix: %w\", err)\n    }\n    return err // classify timeouts/resets separately\n}","preventionTips":["Keep both endpoints on matching protocol versions and padding presets to avoid desync-driven EOFs.","Set read deadlines per packet.","Log the packet ID/field being read when failures cluster."],"tags":["go","network","io","protocol-framing"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}