{"record":{"id":"2a02949cf8632410","repo":"XTLS/Xray-core","slug":"failed-to-write-addons-protobuf-value","errorCode":null,"errorMessage":"failed to write addons protobuf value","messagePattern":"failed to write addons protobuf value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"proxy/vless/encoding/addons.go","lineNumber":28,"sourceCode":"\t\"github.com/xtls/xray-core/common/protocol\"\n\t\"github.com/xtls/xray-core/common/session\"\n\t\"github.com/xtls/xray-core/proxy\"\n\t\"github.com/xtls/xray-core/proxy/vless\"\n\t\"google.golang.org/protobuf/proto\"\n)\n\nfunc EncodeHeaderAddons(buffer *buf.Buffer, addons *Addons) error {\n\tswitch addons.Flow {\n\tcase vless.XRV:\n\t\tbytes, err := proto.Marshal(addons)\n\t\tif err != nil {\n\t\t\treturn errors.New(\"failed to marshal addons protobuf value\").Base(err)\n\t\t}\n\t\tif err := buffer.WriteByte(byte(len(bytes))); err != nil {\n\t\t\treturn errors.New(\"failed to write addons protobuf length\").Base(err)\n\t\t}\n\t\tif _, err := buffer.Write(bytes); err != nil {\n\t\t\treturn errors.New(\"failed to write addons protobuf value\").Base(err)\n\t\t}\n\tdefault:\n\t\tif err := buffer.WriteByte(0); err != nil {\n\t\t\treturn errors.New(\"failed to write addons protobuf length\").Base(err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc DecodeHeaderAddons(buffer *buf.Buffer, reader io.Reader) (*Addons, error) {\n\taddons := new(Addons)\n\tbuffer.Clear()\n\tif _, err := buffer.ReadFullFrom(reader, 1); err != nil {\n\t\treturn nil, errors.New(\"failed to read addons protobuf length\").Base(err)\n\t}\n\n\tif length := int32(buffer.Byte(0)); length != 0 {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/vless/encoding/addons.go#L10-L46","documentation":"After successfully writing the one-byte length, Xray writes the marshaled addons protobuf bytes into the header buffer. Buffer.Write fails only when the serialized addons exceed the remaining buffer capacity — i.e. a addons message larger than ~2KB, which the current schema cannot produce. Internal invariant; not expected at runtime.","triggerScenarios":"A fork adding very large fields to Addons (e.g. long seed/test values) exceeding buf.Buffer capacity; otherwise unreachable.","commonSituations":"Custom builds extending the addons proto with big payloads (Testpre/Testseed experiments) without resizing buffers.","solutions":["Use official builds; if extending addons in a fork, cap field sizes or enlarge the buffer","Report upstream with the config that triggered it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := encoding.EncodeHeaderAddons(buffer, addons); err != nil {\n\tlog.Warnf(\"addons encode: %v\", err)\n\treturn conn.Close()\n}","preventionTips":["Keep addons payloads small in forks (Testpre/Testseed)","Match client/server versions"],"tags":["vless","xtls","protobuf","encoding","internal"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}