[GH-ISSUE #3387] [Windows][Xray] TUN adapter is created with MTU 65535 — large TLS handshakes are corrupted in transit (bad_record_mac), YouTube/Discord unusable. Setting MTU 1280/1200 fixes it #3239

Open
opened 2026-11-07 17:58:02 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @winkyBrain on GitHub (Nov 3, 2026).
Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/3387

Summary

On Windows, the Xray connection creates the tun2 adapter (tun2socks) without setting an MTU, so Windows falls back to 65535. With that MTU the segment sizes (MSS) handed to the userspace TCP stack (tun2socks) are absurdly large, and TLS records above a certain size reach the server corrupted — the server itself answers with an alert bad_record_mac, i.e. the corruption happens in the client → server direction.

Result: the client shows "Connected", plain sites (google.com, github.com, wikipedia, netflix, instagram, ya.ru) work, but every domain with a large TLS handshake fails — youtube.com, m.youtube.com, youtu.be, googlevideo.com, i.ytimg.com all fail with ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC, discord.com fails with ERR_SSL_INVALID_SESSION_ID. For a user this looks like "Xray breaks YouTube" while AmneziaWG on the same server and network works fine.

Setting the adapter MTU manually fixes it completely:

netsh interface ipv4 set subinterface "tun2" mtu=1200 store=active

Environment

Item Value
Client AmneziaVPN 5.0.3.0
OS Windows 10 Pro 22H2, build 10.0.19045.6456
Protocol Xray (VLESS + REALITY), port 443/tcp, default SNI/fingerprint
Tunnel adapter tun2, description "tun2socks Tunnel 2"
Server Self-hosted VPS, Ubuntu + Docker; the same server also runs AWG
Network Home Wi-Fi/Ethernet, 1500-byte path; same key on Android LTE works

Server-side is proven healthy: with AmneziaWG against the same server, same device, same network:

  • https://www.youtube.com → 200, 0.97 MB, 802 ms
  • 3 MB download → 200, 546 ms (~44 Mbps), latest handshake present in awg show

Steps to reproduce

  1. Install Xray (VLESS + REALITY) on a self-hosted server and connect from AmneziaVPN 5.0.3.0 on Windows.

  2. Check the adapter MTU:

    netsh interface ipv4 show subinterfaces
    
    MTU    MediaSenseState   Bytes In    Bytes Out   Interface
    -----  ---------------   ----------  ----------  ---------
    65535  1                 14492795    20015835    tun2
    
  3. Try to open https://www.youtube.com (or Discord) → the handshake fails; google.com opens fine.

  4. Set the MTU, nothing else:

    netsh interface ipv4 set subinterface "tun2" mtu=1200 store=active
    
  5. Repeat step 3 → everything works.

A/B on the adapter MTU (same machine, same server, same network, back-to-back)

MTU youtube.com i.ytimg.com github.com DNS A 3-10 MB download
65535 (default) FAIL bad_record_mac 338 ms FAIL bad_record_mac FAIL timeout 8 s FAIL timeout 3 MB / 2023 ms
1380 FAIL bad_record_mac 338 ms FAIL bad_record_mac OK 338 ms OK 3 MB / 1127 ms
1200 OK 200, ~1.1 s OK 334 ms OK 330 ms OK 10 MB / ~5.0 s

Note that the failure is not a timeout but a deterministic protocol error at ~330 ms, and reducing MTU 65535 → 1380 already fixed github and DNS while leaving YouTube broken — the breakage depends on the size of the TLS flight, not on reachability.

Throughput is not affected by the workaround

Lowering the TUN MTU costs nothing in practice — it only increases the packet count per byte, and the tunnel is not packet-rate bound:

  • Speedtest (browser) with mtu=1200: 214 Mbps down / 498 Mbps up
  • Parallel HTTPS downloads through the tunnel from the same machine at mtu=1200:
Streams Transferred Time Aggregate
1 9.5 MB 4764 ms ~17 Mbps
4 38.1 MB 4586 ms ~70 Mbps
8 76.3 MB 5922 ms ~108 Mbps

So a single stream is limited by RTT/TCP window, not by MTU; aggregate throughput is in the hundreds of Mbps. Setting a sane TUN MTU by default (1280–1380) therefore costs users nothing and fixes a "everything is connected but nothing loads" class of bug.

It is not SNI filtering / DPI / a broken route — isolation tests

All connections are confirmed to go through the tunnel (the local socket address is 10.33.0.2 for every destination; exit IP from https://api.ipify.org is the server's IP).

To rule out anything network-side sniffing the destination, the same destination IP was probed with different server_name values:

Destination IP SNI Result
YouTube IP 142.251.153.4 www.youtube.com FAIL bad_record_mac, 369 ms
Google IP 142.251.152.119 www.youtube.com FAIL bad_record_mac, 341 ms
YouTube IP 142.251.153.4 www.google.com OK 282 ms, CN=www.google.com
Google IP 142.251.152.119 www.google.com OK 285 ms, CN=www.google.com

Identical IP, identical route, identical MTU — the failure follows the SNI. That means the difference is purely the size of the server's TLS flight (YouTube's is the largest), not any per-destination routing or filtering.

Additional confirmation that the corruption is on the upload path: with TLSv1.2 + ALPN h2 the peer answered with an alert rather than a local decode error:

TLS1.3 + h1   ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC  363 ms
TLS1.2 + h1   TIMEOUT                                      8017 ms
TLS1.2 + h2   ERR_SSL_SSL/TLS_ALERT_BAD_RECORD_MAC         407 ms   <-- alert sent by the server
TLS1.3 + h2   ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC  355 ms

The server receiving a corrupted ClientHello and answering bad_record_mac is only possible if the bytes were mangled between the client's TCP stack and the tunnel.

Observed side effects that disappeared after the MTU fix

  • nslookup google.com — DNS request timed out on the A query, AAAA answered (DNS goes through the tunnel). Resolves normally after the MTU fix.
  • ping 8.8.8.8 — 100% loss. Expected and not a bug (tun2socks does not proxy ICMP), but it is what makes users conclude "the tunnel is dead".
  • Mixed results on the same run (api.ipify.org timeout while www.google.com 200) — consistent with large responses being corrupted.

The adapter is recreated from scratch on every reconnect, so a per-interface fix does not stick

Measured across one disconnect/reconnect cycle on the same machine:

before reconnect after reconnect
Adapter GUID (Control\Network\...\Connection) {D823AC1C-5462-462C-85D8-F420B850FC36} {ABEF6F36-5410-4E40-96C6-5F2909640AC3}
Interface index (netsh interface ipv4 show interfaces) 30 29
tun2 MTU 1200 (set manually) 65535 (default again)

The GUID changes every connect, so setting MTU once in HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{GUID} cannot help — the key belongs to a dead adapter next time. This is the same root problem as #3343 ("xray: use a fixed wintun guid on windows"); fixing the GUID would also make a stable per-adapter configuration possible.

Root cause (hypothesis)

  1. The adapter is created by XrayProtocol::startTun2Socks() via the helper's createTun(tunName, ...) call, with no MTU argument (client/core/protocols/xrayProtocol.cpp, tunName = "tun2" on Windows). Windows defaults a Wintun adapter with no MTU to 65535.
  2. Windows' TCP stack therefore sizes segments from a 65535-byte MTU (MSS ≈ 65495) and hands multi-KB buffers to tun2socks.
  3. tun2socks cannot carry a 65495-byte "segment" over a stream to the local Xray SOCKS inbound correctly: multi-part writes get corrupted, which shows up exactly on the biggest TLS flights (YouTube, googlevideo, Discord) and almost never on small ones.
  4. Lowering the MTU forces the client stack to split into 1160/1340-byte segments, and everything works.

Suggested fixes

  1. Set the MTU explicitly when creating the TUN (e.g. 1280 — the value Amnezia already uses for its mobile clients, protocols::awg::defaultMtu on Android/iOS) instead of relying on the Windows default. This alone fixes the reported symptom.
  2. Expose an MTU field in the Xray settings UI. Related: #3219 (MTU field for AWG/WireGuard server settings) — the same is needed for the Xray client TUN.
  3. Re-apply the MTU on every connect: the adapter is deleted and recreated on each connection (iface->deleteTun(tunName) / createTun), so a one-time user-side value is lost after reconnect.
  4. Optional hardening: refuse to start the TUN with an MTU above the path MTU (e.g. warn when MTU > 1500).

Why this is worth fixing rather than closing

  • It makes Xray unusable on Windows for the most popular destinations, while the app still reports "Connected" — the worst possible failure mode for triage.
  • Xray/REALITY is the only protocol that works for many users on mobile carriers that block UDP; those users are exactly the ones who will hit this on desktop next.
  • Related reports of "Connected but nothing works" on Windows: #3197, #3198, #3146. This issue is a concrete, reproducible instance with a one-command workaround.

Minimal reproduction script (Node.js, no dependencies)

import tls from 'node:tls';

const cases = [
  ['youtube IP + youtube SNI', '142.251.153.4',   'www.youtube.com'],
  ['google  IP + youtube SNI', '142.251.152.119', 'www.youtube.com'],
  ['youtube IP + google  SNI', '142.251.153.4',   'www.google.com'],
  ['google  IP + google  SNI', '142.251.152.119', 'www.google.com'],
];

for (const [label, ip, sni] of cases) {
  const res = await new Promise(resolve => {
    const t0 = Date.now();
    const s = tls.connect({ host: ip, port: 443, servername: sni, family: 4, timeout: 8000,
                            ALPNProtocols: ['http/1.1'], rejectUnauthorized: false }, () => {
      const c = s.getPeerCertificate();
      resolve(`ok ${Date.now() - t0}ms cn=${(c && c.subject && c.subject.CN) || '?'}`);
      s.end();
    });
    s.on('timeout', () => { s.destroy(); resolve(`TIMEOUT ${Date.now() - t0}ms`); });
    s.on('error', e => resolve(`ERR ${e.code} ${Date.now() - t0}ms`));
  });
  console.log(label.padEnd(28) + res);
}

With the default MTU: rows 1–2 fail, rows 3–4 pass. With mtu=1200: all four pass.

Originally created by @winkyBrain on GitHub (Nov 3, 2026). Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/3387 ## Summary On Windows, the Xray connection creates the `tun2` adapter (tun2socks) **without setting an MTU**, so Windows falls back to **65535**. With that MTU the segment sizes (MSS) handed to the userspace TCP stack (tun2socks) are absurdly large, and TLS records above a certain size reach the server corrupted — the server itself answers with an alert `bad_record_mac`, i.e. the corruption happens in the **client → server** direction. Result: the client shows "Connected", plain sites (google.com, github.com, wikipedia, netflix, instagram, ya.ru) work, but every domain with a large TLS handshake fails — `youtube.com`, `m.youtube.com`, `youtu.be`, `googlevideo.com`, `i.ytimg.com` all fail with `ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC`, `discord.com` fails with `ERR_SSL_INVALID_SESSION_ID`. For a user this looks like "Xray breaks YouTube" while AmneziaWG on the same server and network works fine. Setting the adapter MTU manually fixes it completely: ``` netsh interface ipv4 set subinterface "tun2" mtu=1200 store=active ``` ## Environment | Item | Value | |----------------|----------------------------------------------------------------------| | Client | AmneziaVPN 5.0.3.0 | | OS | Windows 10 Pro 22H2, build `10.0.19045.6456` | | Protocol | Xray (VLESS + REALITY), port 443/tcp, default SNI/fingerprint | | Tunnel adapter | `tun2`, description "tun2socks Tunnel 2" | | Server | Self-hosted VPS, Ubuntu + Docker; the same server also runs AWG | | Network | Home Wi-Fi/Ethernet, 1500-byte path; same key on Android LTE works | Server-side is proven healthy: with AmneziaWG against the same server, same device, same network: - `https://www.youtube.com` → 200, 0.97 MB, 802 ms - 3 MB download → 200, 546 ms (~44 Mbps), `latest handshake` present in `awg show` ## Steps to reproduce 1. Install Xray (VLESS + REALITY) on a self-hosted server and connect from AmneziaVPN 5.0.3.0 on Windows. 2. Check the adapter MTU: ``` netsh interface ipv4 show subinterfaces ``` ``` MTU MediaSenseState Bytes In Bytes Out Interface ----- --------------- ---------- ---------- --------- 65535 1 14492795 20015835 tun2 ``` 3. Try to open `https://www.youtube.com` (or Discord) → the handshake fails; `google.com` opens fine. 4. Set the MTU, nothing else: ``` netsh interface ipv4 set subinterface "tun2" mtu=1200 store=active ``` 5. Repeat step 3 → everything works. ## A/B on the adapter MTU (same machine, same server, same network, back-to-back) | MTU | youtube.com | i.ytimg.com | github.com | DNS A | 3-10 MB download | |-----------------|----------------------------|---------------------|------------------|--------------|------------------| | 65535 (default) | FAIL bad_record_mac 338 ms | FAIL bad_record_mac | FAIL timeout 8 s | FAIL timeout | 3 MB / 2023 ms | | 1380 | FAIL bad_record_mac 338 ms | FAIL bad_record_mac | OK 338 ms | OK | 3 MB / 1127 ms | | **1200** | OK 200, ~1.1 s | OK 334 ms | OK 330 ms | OK | 10 MB / ~5.0 s | Note that the failure is **not** a timeout but a deterministic protocol error at ~330 ms, and reducing MTU 65535 → 1380 already fixed github and DNS while leaving YouTube broken — the breakage depends on the size of the TLS flight, not on reachability. ## Throughput is not affected by the workaround Lowering the TUN MTU costs nothing in practice — it only increases the packet count per byte, and the tunnel is not packet-rate bound: - Speedtest (browser) with `mtu=1200`: **214 Mbps down / 498 Mbps up** - Parallel HTTPS downloads through the tunnel from the same machine at `mtu=1200`: | Streams | Transferred | Time | Aggregate | |---------|-------------|---------|-----------| | 1 | 9.5 MB | 4764 ms | ~17 Mbps | | 4 | 38.1 MB | 4586 ms | ~70 Mbps | | 8 | 76.3 MB | 5922 ms | ~108 Mbps | So a single stream is limited by RTT/TCP window, not by MTU; aggregate throughput is in the hundreds of Mbps. Setting a sane TUN MTU by default (1280–1380) therefore costs users nothing and fixes a "everything is connected but nothing loads" class of bug. ## It is not SNI filtering / DPI / a broken route — isolation tests All connections are confirmed to go through the tunnel (the local socket address is `10.33.0.2` for every destination; exit IP from `https://api.ipify.org` is the server's IP). To rule out anything network-side sniffing the destination, the same destination IP was probed with different `server_name` values: | Destination IP | SNI | Result | |---------------------------|-----------------|------------------------------| | YouTube IP 142.251.153.4 | www.youtube.com | FAIL bad_record_mac, 369 ms | | Google IP 142.251.152.119 | www.youtube.com | FAIL bad_record_mac, 341 ms | | YouTube IP 142.251.153.4 | www.google.com | OK 282 ms, CN=www.google.com | | Google IP 142.251.152.119 | www.google.com | OK 285 ms, CN=www.google.com | Identical IP, identical route, identical MTU — the failure follows the SNI. That means the difference is purely the **size of the server's TLS flight** (YouTube's is the largest), not any per-destination routing or filtering. Additional confirmation that the corruption is on the upload path: with `TLSv1.2 + ALPN h2` the peer answered with an **alert** rather than a local decode error: ``` TLS1.3 + h1 ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 363 ms TLS1.2 + h1 TIMEOUT 8017 ms TLS1.2 + h2 ERR_SSL_SSL/TLS_ALERT_BAD_RECORD_MAC 407 ms <-- alert sent by the server TLS1.3 + h2 ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 355 ms ``` The server receiving a corrupted ClientHello and answering `bad_record_mac` is only possible if the bytes were mangled **between the client's TCP stack and the tunnel**. ## Observed side effects that disappeared after the MTU fix - `nslookup google.com` — `DNS request timed out` on the A query, AAAA answered (DNS goes through the tunnel). Resolves normally after the MTU fix. - `ping 8.8.8.8` — 100% loss. Expected and **not** a bug (tun2socks does not proxy ICMP), but it is what makes users conclude "the tunnel is dead". - Mixed results on the same run (`api.ipify.org` timeout while `www.google.com` 200) — consistent with large responses being corrupted. ## The adapter is recreated from scratch on every reconnect, so a per-interface fix does not stick Measured across one disconnect/reconnect cycle on the same machine: | | before reconnect | after reconnect | |---|---|---| | Adapter GUID (`Control\Network\...\Connection`) | `{D823AC1C-5462-462C-85D8-F420B850FC36}` | `{ABEF6F36-5410-4E40-96C6-5F2909640AC3}` | | Interface index (`netsh interface ipv4 show interfaces`) | 30 | 29 | | `tun2` MTU | 1200 (set manually) | 65535 (default again) | The GUID changes every connect, so setting `MTU` once in `HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{GUID}` cannot help — the key belongs to a dead adapter next time. This is the same root problem as #3343 ("xray: use a fixed wintun guid on windows"); fixing the GUID would also make a stable per-adapter configuration possible. ## Root cause (hypothesis) 1. The adapter is created by `XrayProtocol::startTun2Socks()` via the helper's `createTun(tunName, ...)` call, with no MTU argument (`client/core/protocols/xrayProtocol.cpp`, `tunName = "tun2"` on Windows). Windows defaults a Wintun adapter with no MTU to **65535**. 2. Windows' TCP stack therefore sizes segments from a 65535-byte MTU (MSS ≈ 65495) and hands multi-KB buffers to tun2socks. 3. tun2socks cannot carry a 65495-byte "segment" over a stream to the local Xray SOCKS inbound correctly: multi-part writes get corrupted, which shows up exactly on the biggest TLS flights (YouTube, googlevideo, Discord) and almost never on small ones. 4. Lowering the MTU forces the client stack to split into 1160/1340-byte segments, and everything works. ## Suggested fixes 1. **Set the MTU explicitly when creating the TUN** (e.g. 1280 — the value Amnezia already uses for its mobile clients, `protocols::awg::defaultMtu` on Android/iOS) instead of relying on the Windows default. This alone fixes the reported symptom. 2. **Expose an MTU field in the Xray settings UI.** Related: #3219 (MTU field for AWG/WireGuard server settings) — the same is needed for the Xray client TUN. 3. Re-apply the MTU on **every** connect: the adapter is deleted and recreated on each connection (`iface->deleteTun(tunName)` / `createTun`), so a one-time user-side value is lost after reconnect. 4. Optional hardening: refuse to start the TUN with an MTU above the path MTU (e.g. warn when MTU > 1500). ## Why this is worth fixing rather than closing - It makes Xray **unusable on Windows** for the most popular destinations, while the app still reports "Connected" — the worst possible failure mode for triage. - Xray/REALITY is the only protocol that works for many users on mobile carriers that block UDP; those users are exactly the ones who will hit this on desktop next. - Related reports of "Connected but nothing works" on Windows: #3197, #3198, #3146. This issue is a concrete, reproducible instance with a one-command workaround. ## Minimal reproduction script (Node.js, no dependencies) ```js import tls from 'node:tls'; const cases = [ ['youtube IP + youtube SNI', '142.251.153.4', 'www.youtube.com'], ['google IP + youtube SNI', '142.251.152.119', 'www.youtube.com'], ['youtube IP + google SNI', '142.251.153.4', 'www.google.com'], ['google IP + google SNI', '142.251.152.119', 'www.google.com'], ]; for (const [label, ip, sni] of cases) { const res = await new Promise(resolve => { const t0 = Date.now(); const s = tls.connect({ host: ip, port: 443, servername: sni, family: 4, timeout: 8000, ALPNProtocols: ['http/1.1'], rejectUnauthorized: false }, () => { const c = s.getPeerCertificate(); resolve(`ok ${Date.now() - t0}ms cn=${(c && c.subject && c.subject.CN) || '?'}`); s.end(); }); s.on('timeout', () => { s.destroy(); resolve(`TIMEOUT ${Date.now() - t0}ms`); }); s.on('error', e => resolve(`ERR ${e.code} ${Date.now() - t0}ms`)); }); console.log(label.padEnd(28) + res); } ``` With the default MTU: rows 1–2 fail, rows 3–4 pass. With `mtu=1200`: all four pass.
Sign in to join this conversation.
No labels
pull-request
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
amnezia-vpn/amnezia-client#3239
No description provided.