[PR #6330] [MERGED] fix(amneziawg): H1-H4 generator + queue-depth throughput fixes #6220

Closed
opened 2026-11-02 04:07:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6330
Author: @kuzzrus
Created: 8/25/2026
Status: ✅ Merged
Merged: 9/3/2026
Merged by: @MHSanaei

Base: main ← Head: fix/awg-h-values-and-queue-depth


📝 Commits (4)

  • 6a8ca28 fix(amneziawg): stop H1-H4 generator misclassifying transport packets
  • 6b73226 fix(amneziawgnet): raise tunQueueDepth to absorb slow-start bursts
  • ba83255 fix(amneziawg): trim comment blocks to the repo's 2-line cap
  • 2bd2ebf Merge remote-tracking branch 'origin/main' into pr/6330

📊 Changes

6 files changed (+40 additions, -42 deletions)

View changed files

📝 docs/content/docs/en/config/amneziawg.mdx (+4 -4)
📝 frontend/src/lib/xray/amneziawg-obfuscation.ts (+5 -9)
📝 frontend/src/test/amneziawg-obfuscation.test.ts (+14 -2)
📝 internal/amneziawg/params.go (+5 -11)
📝 internal/amneziawg/params_test.go (+10 -15)
📝 internal/amneziawgnet/netstack.go (+2 -1)

📄 Description

Summary

Two independent fixes for AmneziaWG throughput, both found and live-tested while investigating #6303 ("AmneziaWG import speed is extremely poor").

1. H1-H4 generator: single value instead of a range

GenerateObfuscation31 (and its frontend mirror, generateAwgObfuscation) picked a random range for each of H1-H4, with only a minimum width enforced (hMinWidth = 1000), no maximum. amneziawg-go's packet classifier (DeterminePacketTypeAndPadding) only ever compares a fixed-size ciphertext prefix against these bounds to decide "handshake vs. transport" — so a wider range buys zero DPI resistance (the range boundaries themselves are never observable on the wire, only whichever single value the classifier lets through matters). It does cost real throughput: randomTrailers is generated true here, and with it on, amneziawg-go's handshake-size checks relax from == to >, so a wide H-range starts misclassifying a proportional fraction of ordinary transport packets as handshakes and silently dropping them. This was independently found and filed the same week as amnezia-vpn/amneziawg-go#183, with a synthetic-packet regression test proving the mechanism.

Live-tested on two boxes, single-variable (only H1-H4 narrowed, nothing else changed): upload went from 2-3 Mbit/s to 200+ Mbit/s on one, and a flat ~20 Mbit/s to 120-156 Mbit/s on another.

A single value per H field is strictly safer than any range — the same reasoning @alekskomp's own native-Amnezia-Docker config in #6303 already uses (H1=1, H2=2, H3=3, H4=4). This changes what the generator produces, not what's accepted: a manually-entered range still validates fine (ValidateObfuscation/validateUintRange untouched).

Fixed in both places that generate these values, since they're independent implementations that could silently drift apart again: internal/amneziawg/params.go (Go, server-side) and frontend/src/lib/xray/amneziawg-obfuscation.ts (what the inbound form's "Regenerate" button calls).

2. tunQueueDepth: 1024 → 8192

A separate contributor to the same "AmneziaWG slower than expected" symptom, specifically on the download side. 1024 was originally sized for a single-connection buffering problem (the gVisor-to-amneziawg-go TUN handoff channel — see the pre-existing comment above the constant). Watching tcpip.Stack.Stats() live during a real many-connection download (20-28 concurrent TCP flows, e.g. a segmented speed test) showed SlowStartRetransmits jump by ~770 in a single second the moment CurrentEstablished crossed ~20 — consistent with several connections' simultaneous slow-start growth briefly exceeding 1024 outstanding packets, with gVisor's channel endpoint (whose queue.Write is non-blocking and drops silently when full) treating the resulting drops as ordinary network loss.

Context

Both root causes, with the live-test numbers, are written up in more detail in my comment on #6303.

One thing worth flagging for review: GenerateObfuscation31 always turns RandomTrailers on for a freshly generated set (it's a normal toggle a user can flip off afterward, but "on" is what every new/regenerated inbound gets) — which is exactly the setting that makes the H1-H4 misclassification bug bite. This PR doesn't touch that default; a single H-value is safe regardless of randomTrailers, so the two are orthogonal. Flagging only so reviewers have the full picture — not proposing a change there.

Test plan

  • go vet / go test on internal/amneziawg and internal/amneziawgnet
  • tsc --noEmit, oxlint, oxfmt --check, vitest run on the touched frontend files
  • Live-tested the H1-H4 fix on two real servers (numbers above)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6330 **Author:** [@kuzzrus](https://github.com/kuzzrus) **Created:** 8/25/2026 **Status:** ✅ Merged **Merged:** 9/3/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/awg-h-values-and-queue-depth` --- ### 📝 Commits (4) - [`6a8ca28`](https://github.com/MHSanaei/3x-ui/commit/6a8ca284a525f043dfcd6c6b31b9245650149dd8) fix(amneziawg): stop H1-H4 generator misclassifying transport packets - [`6b73226`](https://github.com/MHSanaei/3x-ui/commit/6b73226989698d529d2b993b236dc5409ce44e77) fix(amneziawgnet): raise tunQueueDepth to absorb slow-start bursts - [`ba83255`](https://github.com/MHSanaei/3x-ui/commit/ba832554c3e8bb2b401bf67685f8c387bc0e8b37) fix(amneziawg): trim comment blocks to the repo's 2-line cap - [`2bd2ebf`](https://github.com/MHSanaei/3x-ui/commit/2bd2ebf72e8189fa670d4ac0893b7364cadb6d47) Merge remote-tracking branch 'origin/main' into pr/6330 ### 📊 Changes **6 files changed** (+40 additions, -42 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/config/amneziawg.mdx` (+4 -4) 📝 `frontend/src/lib/xray/amneziawg-obfuscation.ts` (+5 -9) 📝 `frontend/src/test/amneziawg-obfuscation.test.ts` (+14 -2) 📝 `internal/amneziawg/params.go` (+5 -11) 📝 `internal/amneziawg/params_test.go` (+10 -15) 📝 `internal/amneziawgnet/netstack.go` (+2 -1) </details> ### 📄 Description ## Summary Two independent fixes for AmneziaWG throughput, both found and live-tested while investigating #6303 ("AmneziaWG import speed is extremely poor"). ### 1. H1-H4 generator: single value instead of a range `GenerateObfuscation31` (and its frontend mirror, `generateAwgObfuscation`) picked a random *range* for each of H1-H4, with only a minimum width enforced (`hMinWidth = 1000`), no maximum. amneziawg-go's packet classifier (`DeterminePacketTypeAndPadding`) only ever compares a fixed-size ciphertext prefix against these bounds to decide "handshake vs. transport" — so a wider range buys zero DPI resistance (the range boundaries themselves are never observable on the wire, only whichever single value the classifier lets through matters). It does cost real throughput: `randomTrailers` is generated `true` here, and with it on, amneziawg-go's handshake-size checks relax from `==` to `>`, so a wide H-range starts misclassifying a proportional fraction of ordinary transport packets as handshakes and silently dropping them. This was independently found and filed the same week as [amnezia-vpn/amneziawg-go#183](https://github.com/amnezia-vpn/amneziawg-go/issues/183), with a synthetic-packet regression test proving the mechanism. Live-tested on two boxes, single-variable (only H1-H4 narrowed, nothing else changed): upload went from 2-3 Mbit/s to 200+ Mbit/s on one, and a flat ~20 Mbit/s to 120-156 Mbit/s on another. A single value per H field is strictly safer than any range — the same reasoning @alekskomp's own native-Amnezia-Docker config in #6303 already uses (`H1=1, H2=2, H3=3, H4=4`). This changes what the generator produces, not what's accepted: a manually-entered range still validates fine (`ValidateObfuscation`/`validateUintRange` untouched). Fixed in both places that generate these values, since they're independent implementations that could silently drift apart again: `internal/amneziawg/params.go` (Go, server-side) and `frontend/src/lib/xray/amneziawg-obfuscation.ts` (what the inbound form's "Regenerate" button calls). ### 2. `tunQueueDepth`: 1024 → 8192 A separate contributor to the same "AmneziaWG slower than expected" symptom, specifically on the download side. 1024 was originally sized for a single-connection buffering problem (the gVisor-to-amneziawg-go TUN handoff channel — see the pre-existing comment above the constant). Watching `tcpip.Stack.Stats()` live during a real many-connection download (20-28 concurrent TCP flows, e.g. a segmented speed test) showed `SlowStartRetransmits` jump by ~770 in a single second the moment `CurrentEstablished` crossed ~20 — consistent with several connections' simultaneous slow-start growth briefly exceeding 1024 outstanding packets, with gVisor's channel endpoint (whose `queue.Write` is non-blocking and drops silently when full) treating the resulting drops as ordinary network loss. ## Context Both root causes, with the live-test numbers, are written up in more detail in [my comment on #6303](https://github.com/MHSanaei/3x-ui/issues/6303#issuecomment-5416975120). One thing worth flagging for review: `GenerateObfuscation31` always turns `RandomTrailers` on for a freshly generated set (it's a normal toggle a user can flip off afterward, but "on" is what every new/regenerated inbound gets) — which is exactly the setting that makes the H1-H4 misclassification bug bite. This PR doesn't touch that default; a single H-value is safe regardless of `randomTrailers`, so the two are orthogonal. Flagging only so reviewers have the full picture — not proposing a change there. ## Test plan - [x] `go vet` / `go test` on `internal/amneziawg` and `internal/amneziawgnet` - [x] `tsc --noEmit`, `oxlint`, `oxfmt --check`, `vitest run` on the touched frontend files - [x] Live-tested the H1-H4 fix on two real servers (numbers above) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:11 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6220
No description provided.