mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6303] [Bug]: Low speed inbound AmneziaWG #4280
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4280
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shoei1944 on GitHub (Aug 24, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6303
Describe the bug
Very low download speed, while VLESS (Reality/XHTTP) provides significantly higher speeds.
AmneziaWG: DL 0.12 Mbps / UP 4.37 Mbps speedtest
VLESS: DL 200 Mbps / UP 100 Mbps speedtest
How to reproduce the problem
Не нашел
Expected behavior
Didn't find it
Actual behavior
Low speed
Relevant logs
Screenshots
3x-ui version
dev+f13baa9a
Xray-core version
26.7.28
How did you install 3x-ui?
install.sh script
Operating system
Debian 13
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
No — direct access
Before submitting
@github-actions[bot] commented on GitHub (Aug 24, 2026):
Short version: the
SOCKS5 associate ... connection refusedlines in your log are not the cause — they are the Xray restart window. The download collapse is most likely the tunnel MTU versus the AmneziaWG 3.1 per-packet padding the panel enables by default, but I can't confirm that without a few values from your inbound, so I'm asking for them below.First, a note: I can't open images, so I could not read either screenshot. Please paste the values as text.
The log warnings are a red herring
amneziawgnet: dial SOCKS5 control connectioncomes frominternal/amneziawgnet/relay.go:108, reached only from the UDP path (UDPRelay.Handle,relay.go:342). It dials the loopback SOCKS5 inbound that lives inside Xray:So
65107= inbound 7,65105= inbound 5. While Xray is down, that listener does not exist, andHandlecaches nothing on failure — it re-dials and re-logs for every UDP datagram, which is why you get 33 identical lines. In your log every one of them appears beforeXRAY: core: Xray 26.7.28 started, so they are all inside one restart window. Note there is noRelayTCP: SOCKS5 CONNECTwarning (relay.go:78), i.e. TCP relaying into Xray was not failing.What I suspect is actually throttling the download
A new AmneziaWG inbound is created with the MTU field empty (
frontend/src/pages/inbounds/form/protocols/amneziawg.tsx:48-50has no default;createDefaultAmneziawgInboundSettingsatfrontend/src/lib/xray/inbound-defaults.ts:304-322never setsmtu). Withmtuunset the embedded interface falls back to:and the client
.confgets noMTU =line at all (internal/sub/service.go:725-726writes it onlyif server.MTU > 0).Meanwhile the generated 3.1 obfuscation set adds bytes to every data packet:
(
randIntis inclusive on both ends —params.go:27-36. The frontend generator is identical:frontend/src/lib/xray/amneziawg-obfuscation.ts:104,115,122.)The arithmetic I derive from those literals — flagging it as my own derivation, not a repo constant: a 1420-byte inner packet in standard WireGuard framing is 1420 + 32 (type/reserved/receiver/counter + Poly1305 tag) + 8 UDP + 20 IPv4 = 1480 bytes on the wire, i.e. 20 bytes of headroom under a 1500-byte path MTU. S4 alone is 12–27 bytes, before ContentPaddingAddition (up to 64) and RandomTrailers. That contradicts what the repo itself asserts in two places:
internal/amneziawg/params.go:68-69—// Total padding stays <= 64: it rides on full-size transport packets, the same MTU headroom that caps S4 at 32.docs/content/docs/en/config/amneziawg.mdx:52— "Kept<= 64by the generator so a 1420-MTU tunnel doesn't fragment."If that headroom really is 20 bytes and not ≥96, the packets that overflow are exactly the full-size ones — the server → client direction — while your client's smaller upstream packets get through. That matches your 0.12 Mbps down / 4.37 Mbps up asymmetry closely. A second candidate with the same signature is
RandomTrailers, whichinternal/amneziawgnet/device.go:53-59documents as one-sided-fatal: "amneziawg-go's own receive path only accepts an oversized (trailer-padded) packet when the RECEIVING side's own RandomTrailers is also true, so a one-sided setting makes that side's packets start getting silently dropped by the other."I could not read
amneziawg-go's own source in this environment, so I cannot confirm whether it reduces the effective MTU to absorb the configured padding. That is the one thing that decides between "real defect" and "your particular config".Separately, and independent of all the above: AmneziaWG here is fully userspace — amneziawg-go over a gVisor netstack, then a loopback SOCKS5 hop into Xray (
internal/amneziawgnet/relay.go:1-6,internal/web/service/xray.go:748-755). It will never match VLESS/Reality throughput. But 0.12 Mbps is far below any constant-factor overhead, so "userspace is slower" does not explain your numbers.What I need from you
SOCKS5 associate ... connection refusedwarnings keep appearing afterXray ... started, or only in that one restart window? If they continue, that is a different and more serious problem than the one above..conf/ re-import the share link (an already-imported profile keeps the old settings), reconnect, and re-run the speed test. If download jumps, the padding-vs-MTU interaction is confirmed. If it doesn't move, blank RandomTrailers on the inbound, re-export the config again, and retest.While testing, the panel Overview's AmneziaWG log view (per-peer
Up/Downcounters,internal/web/service/server.go:1195-1206) is worth watching: a server-sideDownfar larger than what the client reports receiving means packets are being sent and dropped in flight, which is what both hypotheses above predict.Verdict: Insufficient information
Severity: N/A pending the values above; if the MTU/padding derivation holds it is High (default configuration, common path)
Confidence: Medium
Root cause: Not established. Leading candidate:
internal/amneziawgnet/device.go:19defaultMTU = 1420combined with the per-packet paddinginternal/amneziawg/params.go:57,70-71,94enables by default (S4 12–27, ContentPaddingAddition up to 64, RandomTrailers on) while the inbound's MTU field defaults to empty (frontend/src/lib/xray/inbound-defaults.ts:304-322) and noMTU =line reaches the client config (internal/sub/service.go:725-726). Not the log warnings: those arerelay.go:108during the Xray restart window, since the SOCKS5 relay listener lives inside Xray (internal/web/service/xray.go:748-755).Already fixed: Not applicable — still present on the default branch.
internal/amneziawgnet,internal/amneziawgandinternal/web/service/inbound_amneziawg.gohave exactly one commit in their history,effccccefeat(amneziawg): add native AmneziaWG protocol support (#6105), andgit log effcccce..HEADon those paths is empty. The reporter'sdev+f13baa9ais two commits aftereffcccce, so their AmneziaWG code is byte-identical to tip and to v3.7.0.Duplicate of: None. Related: #6302 (AmneziaWG outbounds, a feature request — different code path).
Evidence:
internal/amneziawgnet/relay.go:108return nil, fmt.Errorf("amneziawgnet: dial SOCKS5 control connection: %w", err);relay.go:340-346(no negative caching, so one dial + one warning per datagram);relay.go:78(the TCP-path warning, absent from the log);internal/amneziawgnet/socks_config.go:12-18(port = 65100 + inbound id, matching 65107/65105);internal/amneziawgnet/device.go:19,126-128(defaultMTU = 1420);internal/amneziawgnet/device.go:53-59(RandomTrailers is one-sided-fatal);internal/amneziawg/params.go:27-36,57,68-71,94;internal/sub/service.go:725-726,763-764;internal/web/service/xray.go:712-756;frontend/src/lib/xray/inbound-defaults.ts:304-322;frontend/src/lib/xray/amneziawg-obfuscation.ts:104,115,122;docs/content/docs/en/config/amneziawg.mdx:52,64-70.Not determined: Whether amneziawg-go subtracts the configured S4 / ContentPaddingAddition / RandomTrailers bytes from the effective MTU before emitting a transport packet. Its source is not available in this checkout, and I cannot run or benchmark anything here. Item 4 above (MTU 1280 + re-exported client config) settles it in one test.
This reply was generated automatically; a maintainer may follow up.
@letsnotencrypt commented on GitHub (Aug 24, 2026):
same, with multiple [TUN] [********] Received packet with invalid mac1 in logs
amneziawg client 3.1.0v. with awg3.1 support
@egorbr4z commented on GitHub (Aug 24, 2026):
It fixed it for me when I removed the forced MTU value
@shoei1944 commented on GitHub (Aug 24, 2026):
i try null and 1480/1280 mtu, it doesnt help me
@letsnotencrypt commented on GitHub (Aug 24, 2026):
disabling the RandomTrailers option under the Protocol settings helped me significantly increase the bandwidth, as well as get rid of the "Packet received with invalid mac1" errors. DisableCookies can still cause some log failures from time to time.
@shoei1944 commented on GitHub (Aug 24, 2026):
@mikop63 commented on GitHub (Aug 24, 2026):
AmneziaWG connection is established intermittently, but websites do not load
I am unable to establish a working AmneziaWG connection. Sometimes the connection appears to be established, but websites still do not load.
Configuration in 3x-ui:
Logs from the Amnezia application:
I have tried the following:
RandomTrailers.DisableCookies.None of these changes resolved the issue. The connection may occasionally appear to be established, but I still cannot open any websites.
@mr-darkwing-duck commented on GitHub (Aug 24, 2026):
confirmed:
AWG 10 mbit
VLESS 300 mbit
same VPS, same client
@letsnotencrypt commented on GitHub (Aug 24, 2026):
i tried it on my second work stand with a fresh x-ui installation and met the same conditions.
@shoei1944 commented on GitHub (Aug 24, 2026):
iperf3 test
@MarketTwits commented on GitHub (Aug 25, 2026):
Reproduced on 3x-ui 3.7.0. Same VPS/client: VLESS and native AWG are fast, but 3x-ui AmneziaWG download is much slower. MTU 1280 improved upload only. RandomTrailers off, ContentPaddingAddition disabled, S4=12 and DisableCookies off did not improve download. CPU load stays normal during the test.
@kuzzrus commented on GitHub (Aug 25, 2026):
Traced this to a specific field, with a clean isolation test. Two separate findings, since they overlap in this thread:
Finding 1: MTU overflow (real, but only explains part of the gap)
S4(unlikeS1/S2) prefixes every transport/data packet, not just the handshake —amneziawg-go'suapi.gostores it intopaddings.transport. Wire size of one full packet isMTU + 32 (transport header + poly1305 tag) + S4 + 8 (UDP) + 20 (IPv4). With a 1420-1428 MTU andS4in the high teens/20s (well within this fork's/the panel's generated range), that overflows a 1500-byte path MTU, WireGuard sets DF, and the oversized direction (mostly server→client) just drops. Lowering MTU to 1280 fixed the asymmetry but didn't get us anywhere near native speeds — which led to finding 2.Finding 2:
RandomTrailers(the dominant factor, isolated field-by-field)Same VPS, same client app, same MTU (1280), same
S1-S4, only the listed field changed each round:HeaderProtectionKeyContentPaddingAdditionRandomTrailersDisableCookies(*third and fourth row: clearing
HeaderProtectionKeyalone changed nothing; flipping onlyRandomTrailersoff on top of that fixed it. A follow-up round restoredHeaderProtectionKeywithRandomTrailersstill off and speed stayed good — soHeaderProtectionKeydoesn't correlate with throughput at all, onlyRandomTrailersdoes.)This matches @MarketTwits' report of RandomTrailers/S4/ContentPaddingAddition/DisableCookies not moving the needle -- but note their combination didn't isolate
RandomTrailersalone fromHeaderProtectionKey, sinceHeaderProtectionKeywasn't mentioned as cleared in their test. Once isolated,RandomTrailersis the whole effect.We can't yet explain this from the source. In
device/send.go,randomPaddingAddition(driven byContentPaddingAddition) is checked beforepeer.randomTrailer, and returns non-negative wheneverContentPaddingAdditionis set — so by that precedence,RandomTrailersshouldn't touch data packets at all once padding is configured, only the three handshake message types. Whatever's actually happening doesn't match that reading.Ruled out along the way, in case it saves someone a round: (
SendHandshakeCookie'smake([]byte, len, cap)bug) is unrelated here — already fixed as ofv3.1.20260814, and moot regardless sinceSendHandshakeCookiereturns immediately whenDisableCookiesis set (true in every row above).Environment: 3x-ui fork with embedded
amneziawg-go(gVisor netstack + SOCKS5 relay into Xray, not a kernel module),github.com/amnezia-vpn/amneziawg-go/v3 v3.1.20260814, Windows AmneziaVPN desktop client.@shoei1944 commented on GitHub (Aug 25, 2026):
@bazaproject
DNS не влияет на скорость Клиент <-> Сервер
@shoei1944 commented on GitHub (Aug 25, 2026):
@kuzzrus
Поставив ваши параметры AmneziaWG я смог добится адекватной скорости (166/166)
Но улетает нагрузка на ЦП сервера до 70%
Дополнение: На iOS все работает, на ПК также обычный веб работает, но любой speedtest показывает чушь
By setting your AmneziaWG parameters, I was able to achieve adequate speed (166/166)
But the server CPU load to 70%
Addition: Everything works on iOS, and the regular web works on a PC, but any speedtest shows nonsense.
Speedtest: https://www.speedtest.net/result/i/7207354382
@alekskomp commented on GitHub (Aug 25, 2026):
This is default server config from native AmneziaVPN docker container:
Latest native AmneziaVPN server in docker works fine with AmneziaWG
v3.1.20260814client on android.But got slow speed with this config on 3x-ui server.
RandomTrailers = offwith 3x-ui server fixes speed issue@kuzzrus commented on GitHub (Aug 25, 2026):
Follow-up to my earlier comment — root cause found, fix shipped and verified on two real servers.
Root cause of the
RandomTrailerseffectamneziawg-go'sDeterminePacketTypeAndPadding(device/receive.go) tests incoming packets against the H1/H2/H3 handshake ranges before it tests them as transport. WithRandomTrailersenabled, those three tests relax from==to>(a trailer makes a handshake message longer than its fixed size) — but a full-size transport packet is also longer than any handshake message, so the relaxed test matches it too. The only thing left distinguishing a data packet from a handshake at that point is the H-range check on 4 ciphertext bytes — uniformly random from an observer's (and the classifier's) point of view. A wide H-range therefore steals a proportional fraction of every transport packet, silently, with no counter or log line.This was independently found and filed the same day by another author, with a synthetic-packet regression test proving it: amnezia-vpn/amneziawg-go#183 ("~3.5% of transport packets misclassified as handshakes" with their ~50M-wide example ranges).
Why this fork's default made it so much worse than 3.5%
This fork's own H1-H4 generator (
internal/amneziawg/params.go, both the Go copy and a duplicate infrontend/.../InboundFormModal.tsx's "Regenerate" button) picked a random range per field, with only a minimum width enforced — no maximum. Checking the actual value that was live on my own test inbound during this investigation:H1+H2+H3 alone (the three ranges checked before transport) sum to ~15% of the address space — i.e. roughly 15% of transport packets misclassified and dropped, about 4x worse than the reference case in amneziawg-go#183. That tracks with the severity in this thread (0.12 Mbps, 10 Mbit vs 300, etc.) far better than a flat "3.5%" would.
@alekskomp's own posted native-Amnezia-Docker config in this thread is a clean, independent confirmation from the other direction: it uses
H1 = 1,H2 = 2,H3 = 3,H4 = 4— literal single values, zero range width — withRandomTrailers = on, and reportedly works fine. A range costs nothing on the wire (an observer only ever sees the same random ciphertext bytes regardless of how wide the receiver's acceptance window is), so a single value is strictly safer than any range, with no obfuscation trade-off.Live-tested fix
Narrowing only H1-H4 on an already-broken inbound (
RandomTrailers,ContentPaddingAddition, everything else held constant) took upload from 2-3 Mbit/s to 200+ Mbit/s on my test VPS, single-variable, no other change. Confirmed a second time on a real production box: same treatment took it from a flat ~20 Mbit/s to 120-156 Mbit/s across several runs, in line with the other direction on the same box.Separately, I found and fixed an undersized shared outbound packet queue (
internal/amneziawgnet, the gVisorchannel.Endpointbetween the netstack and the WireGuard device) that silently drops packets under several concurrent TCP connections' simultaneous slow-start growth — confirmed via a debug endpoint exposing gVisor's ownstack.Stats()counters live during a real multi-connection transfer. This is a separate contributor to "AmneziaWG is slower than VLESS/native" specifically on the download side, independent ofRandomTrailers.Both fixes are shipped on my fork (kuzzrus/3x-ui-awg,
v3.7.0-awg.7):GenerateObfuscation20and the frontend's independentregenInboundAwgObfuscationcopy — both needed the fix separately, since the frontend port had silently dropped the width cap the Go version originally had, and is the code path the panel's actual "Regenerate" button goes through).Since #6105 merged this fork's AmneziaWG implementation upstream, both of these likely affect
mainhere too — happy to open a PR with both fixes (H1-H4 single-value generation in both places, queue depth) if that's useful.@shoei1944 commented on GitHub (Aug 25, 2026):
Good job!
@alijazizaib commented on GitHub (Aug 26, 2026):
Commenting to share that I experienced the same issue and fixed it by following @kuzzrus settings. Will wait for main line to update . Certainly suggest to issue PR.
@MarketTwits commented on GitHub (Aug 29, 2026):
I confirm, the fix works. Well done, guys!