High RAM consumption when using xhttp
Integrity requirements
- [x] I have read all the comments in the issue template and ensured that this issue meet the requirements.
- [x] I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
- [x] I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
- [x] I searched issues and did not find any similar issues.
- [x] The problem can be successfully reproduced in the latest Release
Description
In Russia, TCP transport stopped working and many switched to xhttp. However, on all iOS clients, using HTTP causes memory consumption to exceed 50 MB over time, which causes iOS to automatically turn off the VPN tunnel.
Reproduction Method
Just use
Client config
{ "outbounds" : [ { "streamSettings" : { "security" : "reality", "realitySettings" : { "serverName" : "-", "fingerprint" : "chrome", "shortId" : "-", "spiderX" : "", "publicKey" : "-" }, "network" : "xhttp", "xhttpSettings" : { "mode" : "packet-up", "path" : "/new-weels", "host" : "-" } }, "settings" : { "address" : "-", "id" : "-", "encryption" : "none", "port" : 443 }, "protocol" : "vless", "tag" : "proxy" }, { "settings" : { "response" : { "type" : "none" } }, "protocol" : "blackhole", "tag" : "block" }, { "settings" : {
},
"protocol" : "freedom",
"tag" : "direct"
}
], "id" : "-", "stats" : {
}, "policy" : { "system" : { "statsOutboundDownlink" : true, "statsOutboundUplink" : true, "statsInboundUplink" : true, "statsInboundDownlink" : true } }, "remarks" : "-", "log" : { "loglevel" : "info" }, "inbounds" : [ { "listen" : "[::1]", "port" : 1080, "settings" : { "udp" : true }, "protocol" : "socks", "tag" : "socks", "sniffing" : { "routeOnly" : false, "enabled" : true, "destOverride" : [ "http", "quic", "tls" ] } } ] }
Server config
{ "tag": "VLESS TCP REALITY", "listen": "0.0.0.0", "port": 443, "protocol": "vless", "settings": { "clients": [], "decryption": "none" }, "streamSettings": { "network": "xhttp", "xhttpSettings": { "path": "/new-weels", "mode": "auto" }, "security": "reality", "realitySettings": { "show": false, "dest": "127.0.0.1:8443", "xver": 0, "serverNames": [ «.» ], "privateKey": «.», "publicKey": «.», "shortIds": [ ".", "." ] } }, "sniffing": { "enabled": true, "destOverride": [ "http", "tls", "quic" ], "metadataOnly": false } }
Client log
2025/11/24 13:57:44.607707 [Warning] core: Xray 25.10.15 started 24.11.2025 13:57:44 XrayCoreStart - {"success":true} app: v3.5.3 24.11.2025 13:59:14 Tunnel stopped. Stop reason: - userInitiated
Server log
Empty
*upd, same problem with tcp transport
The largest memory consumption is observed when watching YouTube
*upd, same problem with tcp transport
The largest memory consumption is observed when watching YouTube
check your client routing, if you use something like a "geosite:category-ads-all" you are cooked bro
check your client routing, if you use something like a "geosite:category-ads-all" you are cooked bro
This is independent of geo files. It happens with geo files disabled. I am aware of the issue with large geo files and checked it immediately.
just use Android
just use Android
👍🏻
just use Android
But what if that's not an option? A lot of people still have ios.
I've run into the same issue with excessive RAM consumption (which never happened with plain VLESS+REALITY) on an OpenWrt router with 256 megabytes of RAM (~140 MB available at startup), with xray-core updated to the latest version, so this problem isn't specific to iOS. There's very likely a memory leak in the XHTTP implementation, because I don't have large geo files or a large number of devices connected to my network.
I've run into the same issue with excessive RAM consumption (which never happened with plain VLESS+REALITY) on an OpenWrt router with 256 megabytes of RAM (~140 MB available at startup), with xray-core updated to the latest version, so this problem isn't specific to iOS. There's very likely a memory leak in the XHTTP implementation, because I don't have large geo files or a large number of devices connected to my network.
For me, the solution was to use the pocket-up mod, which uses less memory.
I've run into the same issue with excessive RAM consumption (which never happened with plain VLESS+REALITY) on an OpenWrt router with 256 megabytes of RAM (~140 MB available at startup), with xray-core updated to the latest version, so this problem isn't specific to iOS. There's very likely a memory leak in the XHTTP implementation, because I don't have large geo files or a large number of devices connected to my network.
For me, the solution was to use the pocket-up mod, which uses less memory.
what “pocket up mode” is?
I've investigated the root causes of the high memory consumption in XHTTP transport and prepared a PR with optimizations that reduce total allocations by ~63% (from ~68 MB down to ~25 MB for a 10 MB transfer).
Root causes found via pprof profiling:
io.ReadAllwith grow-and-copy pattern (512 -> 1K -> 2K -> ... -> target size) on both client and server - accounted for ~52 MB (77%) of all allocationsslices.Concatunconditionally copying payload even when only one source has data - ~10 MB (15%)bytes.Bufferfull HTTP request serialization doubling memory per upload- Unbounded concurrent upload goroutines multiplying in-flight buffer memory
globalDialerMapnever cleaning up dead entries (leak over time)
Profiling results (pprof alloc_space, 10 MB transfer):
| Allocator | Before | After |
|---|---|---|
io.ReadAll + bytes.growSlice |
51.7 MB | 0 MB (eliminated) |
slices.Concat |
10.2 MB | 0 MB (eliminated) |
| Total | 66.6 MB | 24.7 MB (-63%) |
This should significantly help with the iOS 50 MB Network Extension limit and low-memory devices like OpenWrt routers mentioned by @debushoukun.
PR: #5797
FYI, here is another way to reduce RAM overhead of XHTTP in some scenarios: #6268