UDP inbound silently drops bursts: per-session pipe hardcoded to 16 KiB with DiscardOverflow (WireGuard over tunnel/dokodemo collapses to ~1 Mbps)

Open
#7,106 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #7309 by @earmark-halt — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
networking

Research direction

Start with app/proxyman/inbound/worker.go, specifically udpWorker.getConnection, and inspect how the UDP pipe size and overflow policy are configured. The issue also names a second drop point in transport/internet/udp/hub.go; read its channel handling. Run the supplied WireGuard/iperf3 reproduction and compare packet loss before and after a buffer change; done means bursts are no longer silently dropped and drops are observable.

Written by the indexing model from the issue text.

Description

Integrity requirements
  • I have read all the comments in the issue template and ensured that this issue meet the requirements.
  • 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.
  • I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • I searched issues and did not find any similar issues.
  • The problem can be successfully reproduced in the latest Release

Reproduced on v26.7.28. The code involved is identical in v26.9.30 and on main (8989adf, 2026-10-08), but I have not rerun the test on v26.9.30 itself.

Description

Every UDP session on a port-listening UDP inbound (tunnel / dokodemo-door with network: udp) is given a pipe of only 16 KiB with DiscardOverflow():

// app/proxyman/inbound/worker.go (udpWorker.getConnection)
pReader, pWriter := pipe.New(pipe.DiscardOverflow(), pipe.WithSizeLimit(16*1024))

16 KiB holds about 12 full-size WireGuard packets. Any burst bigger than that, arriving faster than the outbound drains it, is thrown away. This happens whenever the outbound stalls briefly, for example while the outer TCP connection waits one RTT for a retransmit. Nothing logs or counts the drop, and the kernel UDP counters (UdpRcvbufErrors) stay at 0 because the packet was already read from the socket.

The UDP hub has a second silent drop point: a 256-entry channel with a select { default: } drop (transport/internet/udp/hub.go).

The common setup this breaks is kernel WireGuard → tunnel UDP inbound → VLESS/REALITY. The inner TCP sees about 1% loss even when the link is idle. Loss-based congestion control (CUBIC, which is also what macOS uses) collapses at long RTTs:

Upload, 1 TCP stream, RTT ≈ 200 ms, line ≈ 47 Mbps Throughput
Raw internet, no proxy 48.4 Mbps
Same path through VLESS + REALITY (TCP via socks inbound) 45.3 Mbps
WireGuard → tunnel UDP inbound → same VLESS + REALITY, inner CUBIC 1.3–2.0 Mbps
Same, inner sender paced (iperf3 --fq-rate 40M) 34.7 Mbps
Same, inner BBR (ignores loss; 2976 retransmits in 15 s) 40.5 Mbps
Same, pipe raised to 1 MiB (patched build) 12.7 Mbps from a Wi-Fi macOS client; 0 drops

Locating the loss: in a 10 s test, comparing WireGuard peer counters (wg show dump) on both ends showed 1.36% of bytes sent by the client never reached the server. No socket on any hop (client, relay, server) reported RcvbufErrors. A patched build with the pipe raised to 1 MiB eliminated the loss and its drop counter stays at 0. I have not yet captured the counter at the stock 16 KiB size; I can add that run if useful.

Things already ruled out in that setup: UDP socket buffers (rmem_default/max = 32 MiB), outer congestion control (BBR on every hop), MTU/PMTU (frag-needed works and MSS is clamped), CPU, routing.

Suggested fix

Make the size configurable, and preferably raise the default. Options, in order of preference:

  1. Use the existing buffer policy (policy.levels.N.bufferSize, xray.ray.buffer.size) for the UDP inbound pipe instead of a hardcoded 16 KiB, while keeping DiscardOverflow so a stuck outbound can't use unbounded memory.
  2. Or add an env flag in the same style as xray.ray.buffer.size (e.g. xray.udp.inbound.buffer.size) and a larger default (e.g. 512 KiB, matching the default per-connection buffer on amd64).
  3. Either way, count dropped packets (stats counter or a debug log) so this isn't invisible.

The patch I tested (about 30 lines: env-configurable pipe size and hub capacity, plus drop counters) is ready to send as a PR if the approach is acceptable.

Reproduction Method

Two hosts A (client) and B (server), kernel WireGuard on both, Xray between them. Add latency/loss on the path between A and B, e.g. tc qdisc add dev eth0 root netem delay 40ms loss 0.1% on a router in between (the real case was a ~140 ms RTT path with natural loss).

  1. Xray on A: a tunnel UDP inbound on 127.0.0.1:51283 forwarding to B's WireGuard port, VLESS + REALITY outbound to B (configs below).
  2. WireGuard on A: peer endpoint 127.0.0.1:51283, MTU 1280.
  3. iperf3 -s on B's WireGuard address; on A (or a LAN host routed through A): iperf3 -c <B wg address> -t 15.
  4. Compare WireGuard peer bytes, tx on A vs rx on B: about 1% of packets are missing, while /proc/net/snmp shows no RcvbufErrors on either side.
  5. Rebuild with pipe.WithSizeLimit(16*1024) → 1024*1024: loss goes to 0 and throughput rises severalfold.
Client config
log:
  loglevel: warning
inbounds:
  - tag: wg-udp
    listen: 127.0.0.1
    port: 51283
    protocol: tunnel
    settings:
      allowedNetwork: udp
      rewriteAddress: 203.0.113.10   # B's public address
      rewritePort: 51280             # B's WireGuard ListenPort
outbounds:
  - protocol: vless
    settings:
      vnext:
        - address: 203.0.113.10
          port: 443
          users:
            - id: 00000000-0000-0000-0000-000000000000
              encryption: none
              flow: xtls-rprx-vision
    streamSettings:
      network: raw
      security: reality
      sockopt: {tcpcongestion: bbr}
      realitySettings:
        serverName: example.com
        fingerprint: chrome
        password: <REALITY public key>
        shortId: "0123456789abcdef"
Server config
log:
  loglevel: warning
inbounds:
  - listen: 0.0.0.0
    port: 443
    protocol: vless
    settings:
      clients:
        - id: 00000000-0000-0000-0000-000000000000
          flow: xtls-rprx-vision
      decryption: none
    streamSettings:
      network: raw
      security: reality
      sockopt: {tcpcongestion: bbr}
      realitySettings:
        target: example.com:443
        serverNames: [example.com]
        privateKey: <REALITY private key>
        shortIds: ["0123456789abcdef"]
outbounds:
  - protocol: freedom
Client log

The stock build prints nothing about the drops, which is part of the problem. With the counting patch and XRAY_UDP_PIPE_KB=1024:

[Warning] app/proxyman/inbound: UDP inbound pipe size: 1048576 bytes
(no "UDP drops" lines during a 15 s iperf3 run)
Server log
Nothing relevant at loglevel warning.
Dominant language
Go
Stars
43.3k
Forks
6.2k
Avg merge
2d 11h
Merged PRs (30d)
55

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from XTLS/Xray-core

All issues in XTLS/Xray-core

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.