mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6416] [Bug]: WireGuard listens on many ports in addition to its own port #4345
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#4345
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 @FPu3EpOBIIIuK on GitHub (Sep 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6416
Describe the bug
When a client connects to WireGuard, for example on port 443, and then you check which ports 3x-ui is listening on, many unknown UDP ports appear. If the client disconnects, the panel still shows it as online, and even more open listening ports appear. When the kernel is restarted, the unknown ports disappear from 3x-ui's listening ports, and the client's status changes to offline.
How to reproduce the problem
Expected behavior
When creating and connecting, only 1 port — the one on which the connection was created — should be opened
Actual behavior
Unknown ports are opened upon connection
Relevant logs
Screenshots
No response
3x-ui version
3.7.0
Xray-core version
26.7.28
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04
Which parts of the panel are affected?
Xray config generation, Backend (API endpoints, login, settings)
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
No response
Before submitting
@github-actions[bot] commented on GitHub (Sep 4, 2026):
Those extra UDP ports are almost certainly not the panel or your inbound listening — for a
wireguardinbound the 3x-ui process opens no UDP socket at all, and whatss -tulpnshows are Xray-core's own per-flow outbound UDP sockets. But I can't close this out yet, because one number nobody has measured decides whether they age out normally or genuinely leak. Details, then what I need.Why the panel is not the one holding those sockets
wireguardis an Xray-core protocol, not a panel-side one. The panel converts your clients into thepeersarray and hands the whole thing to the Xray child process:whose doc comment states the target explicitly: "the peers array xray-core's wireguard inbound expects" (
internal/database/model/model.go:452). Xray-core then owns every socket for that inbound.Grepping the whole Go tree, the panel process creates exactly two kinds of UDP socket, both in
internal/amneziawgnet/:internal/amneziawgnet/relay.go:175—net.DialUDP("udp", nil, net.UDPAddrFromAddrPort(bind))internal/amneziawgnet/portfwd_udp.go:49—(&net.ListenConfig{}).ListenPacket(context.Background(), "udp", ...)and that whole runtime only ever starts for the AmneziaWG protocol, not WireGuard:
Those are two different dropdown entries with completely different implementations — the docs table spells it out:
docs/content/docs/en/config/inbounds.mdx:60-61, WireGuard = "Modern tunnel" (Xray-core), AmneziaWG = "Obfuscated WireGuard fork, embedded in the panel process".Why they look like "listening" ports, and why they go away on a core restart
Two things are worth separating:
-linss -tulpndoes not mean "listening" for UDP — UDP has no listen state, so-lmatches every socket inUNCONN, which includes every unconnected outbound socket a proxy opens to send traffic on your behalf. Nothing is reachable from outside on those ports in the way a service port is. This is not WireGuard-specific: any inbound carrying UDP (DNS, QUIC/HTTP3, games, torrents) produces the same picture.connIdle(internal/web/service/config.json:48-61— level0carries onlystatsUserDownlink/statsUserUplink), so Xray's own default applies. The panel documents that default in its own UI string:So an idle flow's socket is expected to survive up to ~5 minutes after the peer goes quiet. Your step 7 restarted the core well inside that window, which drops every socket at once — the same thing waiting would have done. You can lower it in the panel: Xray Configs → Connection Limits → Idle Timeout (
frontend/src/pages/xray/basics/BasicsTab.tsx:371, writespolicy.levels.0.connIdle; the panel preserves it, it only force-enablesstatsUserOnline—internal/web/service/xray.go:1001).The "still shows as connected" half is the same fact
WireGuard is connectionless: the server never learns a peer left. The panel does not invent an online timer — it takes Xray's answer and ages it out after 20 seconds:
fed by
GetOnlineUsersover Xray's stats API (internal/xray/api.go:808) unioned with per-poll byte deltas (internal/web/job/xray_traffic_job.go:122-137). So the client stays "online" for exactly as long as Xray still holds sessions or moves bytes for that peer — the same lingering sessions that hold the sockets. One cause, two symptoms.What I need to settle it
The one thing that separates "normal flow sockets aging out" from "a real socket leak" is whether the count comes back down on its own. Please, with nothing restarted:
sudo ss -ulpnline for two or three of the unknown ports, as text, including theusers:(("...",pid=...))column — that names the owning process (xrayvsx-ui) and settles the attribution above outright.If the count falls back to baseline in step 2, this is ordinary proxy behaviour and the answer is the
connIdleknob. If it keeps climbing across connect/disconnect cycles and never drops, that is a real socket leak worth chasing — post the numbers here first either way.I could not verify Xray-core's socket handling directly: this checkout pins it as a module (
go.mod:28,github.com/xtls/xray-core v1.260327.1-0.20260728075948-5ca6f4b7d4dc) and its source is not readable here, so the "one unconnected socket per proxied UDP flow" part is inference from the panel side, not something I read in that code.This reply was generated automatically; a maintainer may follow up.
@FPu3EpOBIIIuK commented on GitHub (Sep 4, 2026):
Protocol: WireGuard
Output of the command sudo ss -ulpn
Output of the command sudo ss -uanp | grep -c xray
52
utput of the command sudo ss -uanp | grep -c xray after 6+ minutes
15
@github-actions[bot] commented on GitHub (Sep 4, 2026):
Thanks — your two numbers settle it, and the answer is that this is normal Xray-core behaviour, not a panel bug and not a socket leak. Both open questions from my last comment are now answered by your own output.
1. The sockets belong to Xray-core, not to 3x-ui
Your
ssoutput names the owner asxray-linux-amd6.sstruncates the process name to 15 characters, so that isxray-linux-amd64— which is exactly the string the panel builds when it launches its managed child process:On
linux/amd64that isxray-linux-amd64. None of the sockets are held byx-ui, which confirms the attribution I described last time: for awireguardinbound the panel only emits thepeersarray into the Xray config (internal/database/model/model.go:462) and Xray-core owns every socket from there. The panel's own UDP sockets live only ininternal/amneziawgnet/, gated to the AmneziaWG protocol atinternal/amneziawg/instance.go:28:You confirmed the inbound is
WireGuard, so that runtime never starts.2. The count comes back down on its own — that is the whole test
That is the exact measurement that separates "ordinary flow sockets aging out" from "a real leak", and it decayed on its own with nothing restarted. It matches Xray's
connIdledefault of 300 seconds, which applies because the config template the panel ships sets noconnIdleat all — level0carries onlystatsUserDownlink/statsUserUplink(internal/web/service/config.json:48-61). The panel states that default in its own UI string:Your step 7 in the original report ("restart the kernel") just dropped every socket at once, inside that 5-minute window — the same thing waiting did.
Two things worth keeping in mind about the picture itself:
-linss -tulpndoes not mean "listening" for UDP. UDP has no listen state, so-lmatches every socket inUNCONN, including every unconnected outbound socket a proxy opens to send traffic on your behalf. Nothing is externally reachable on those ports the way your inbound's port is. Any inbound carrying UDP (DNS, QUIC/HTTP3, games, torrents) produces the same picture — it is not WireGuard-specific.frontend/src/pages/xray/basics/BasicsTab.tsx:361-374, writespolicy.levels.0.connIdle; the panel preserves your value and only force-enablesstatsUserOnline—ensureStatsPolicy,internal/web/service/xray.go:1001). The field is empty by default, which means Xray's 300.3. "Still shows as connected" is the same fact, not a second bug
WireGuard is connectionless — the server never learns a peer left. The panel does not invent an online timer; it takes Xray's answer and ages it out after 20 seconds:
fed by
GetOnlineUsersover Xray's stats API (internal/xray/api.go:808) unioned with per-poll byte deltas (internal/web/job/xray_traffic_job.go:122-137). So the client stays "online" exactly as long as Xray still holds sessions for that peer — the same lingering sessions that hold the sockets. One cause, two symptoms, and both clear on the sameconnIdletimer.Closing this as expected behaviour. One honest gap: you did not measure the count before connecting, so I cannot say 15 is precisely your baseline rather than a slightly elevated one. If you ever see it climb monotonically across many connect/disconnect cycles and never return near a measured pre-connection baseline, that would be a different finding — post the baseline number and the series and it can be reopened.
This reply was generated automatically; a maintainer may follow up.